UIButton tag value passing error
I am using a button  test3 to a given tag and calling method when i call method it passes the wrong value code is given below  
int J=4;
	for (int a = 0; a < rowTwo.count; a++) {
	
		if (J==5 || J==7) {
           
			J++;
			
		}
		
		CGRect frame;
		frame.origin.x = self.scrollView1.frame.size.width * a;
		frame.origin.y = 0;
		frame.size = self.scrollView1.frame.size;
		
		
		
		UIView*subView1=[[UIView alloc ]initWithFrame:frame];
		//	subView1.backgroundColor=[colors objectAtIndex:j];
		[self.scrollView1 addSubview:subView1];
		
		CGRect label=CGRectMake(13, 342, 233, 35);

		CGRect myframe=CGRectMake(110, 89, 258, 128);
		
				
		UITextView*textView=[[UITextView alloc] initWithFrame:myframe];
		Book*book=[ rowTwo objectAtIndex:a];
		NSString*mytext=book.teaser;
		mytext = [mytext stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&aring;" withString:@"å"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&oslash;" withString:@"ø"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&Oslash;" withString:@"Ø"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&Aring" withString:@"Å"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		
		
		textView.font=[UIFont fontWithName:@"Times New Roman" size:16];
		textView.text=mytext;		
		CGRect myframe1=CGRectMake(502, 89, 200, 128);
		Book*book1=[rowTwoSecond objectAtIndex:a];
		
		NSString*text2=book1.teaser;
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&aring" withString:@"å"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&oslash" withString:@"ø"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
	
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&Oslash;" withString:@"Ø"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&Aring" withString:@"Å"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		
		
		
		
		UITextView*textViewtwo=[[UITextView alloc] initWithFrame:myframe1];
		textViewtwo.font=[UIFont fontWithName:@"Times New Roman" size:16];
        textViewtwo.text=text2;
		
		
		UIButton*headingButton=[UIButton buttonWithType:UIButtonTypeCustom];
		headingButton.frame=CGRectMake(16, 49, 300, 37);
		NSString*headingbuttontitle=book.title;
		headingbuttontitle = [headingbuttontitle stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		headingbuttontitle = [headingbuttontitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

				
		
		headingButton.tag=J;

		[headingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		[headingButton setTitle:headingbuttontitle forState:UIControlStateNormal];
		
		[headingButton addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		testButton3.tag=J;
		[testButton3 addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		headingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
		headingButton.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];

		UIButton*myImageButton=[UIButton buttonWithType:UIButtonTypeCustom];
		myImageButton.frame=CGRectMake(16, 85, 90, 127);
		NSString*thumb2=book.thumbimgurl;
		thumb2 = [thumb2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		UIImage *image2 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb2]]];
		myImageButton.tag=J;
		[myImageButton setBackgroundImage:image2 forState:UIControlStateNormal];
		// myImageView.image=[UIImage imageNamed:@"thumb.jpg"];
		[myImageButton addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		[subView1 addSubview:myImageButton];

		
		
		
		
		J++;
		
		
		
		
		
		
		
		
		UIButton*headingButton1=[UIButton buttonWithType:UIButtonTypeCustom];
		headingButton1.frame=CGRectMake(407, 49, 300, 37);	
		[headingButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		
		
		NSString*headingbutton1title=book1.title;
		headingbutton1title = [headingbutton1title stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		headingbutton1title = [headingbutton1title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		
		
		
		
		
		
		UIButton*myImageButton1=[UIButton buttonWithType:UIButtonTypeCustom];
		myImageButton1.frame=CGRectMake(407, 85, 90, 127);
		NSString*thumb1=book1.thumbimgurl;
		thumb1 = [thumb1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		thumb1 = [thumb1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		UIImage *image1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb1]]];
		myImageButton1.tag=J;
		[myImageButton1 setBackgroundImage:image1 forState:UIControlStateNormal];
		// myImageView.image=[UIImage imageNamed:@"thumb.jpg"];
		[myImageButton1 addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		testButton4.tag=J;
		
		[testButton4 addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];	
		
		
		[subView1 addSubview:myImageButton1];
		
		
				
		
		
		headingButton1.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];
		headingButton1.tag=J;
		
		[headingButton1 setTitle:headingbutton1title forState:UIControlStateNormal];

		
		[headingButton1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];	

		
		headingButton1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
		
		
		
		
		
		
		[subView1 addSubview:headingButton];
		[subView1 addSubview:headingButton1];
		[subView1 addSubview:textView];
		[subView1 addSubview:textViewtwo];
		
		
		}

UIButton tag value passing error
===

I am using a button  test3 to a given tag and calling method when i call method it passes the wrong value code is given below  
int J=4;
	for (int a = 0; a < rowTwo.count; a++) {
	
		if (J==5 || J==7) {
           
			J++;
			
		}
		
		CGRect frame;
		frame.origin.x = self.scrollView1.frame.size.width * a;
		frame.origin.y = 0;
		frame.size = self.scrollView1.frame.size;
		
		
		
		UIView*subView1=[[UIView alloc ]initWithFrame:frame];
		//	subView1.backgroundColor=[colors objectAtIndex:j];
		[self.scrollView1 addSubview:subView1];
		
		CGRect label=CGRectMake(13, 342, 233, 35);

		CGRect myframe=CGRectMake(110, 89, 258, 128);
		
				
		UITextView*textView=[[UITextView alloc] initWithFrame:myframe];
		Book*book=[ rowTwo objectAtIndex:a];
		NSString*mytext=book.teaser;
		mytext = [mytext stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&aring;" withString:@"å"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&oslash;" withString:@"ø"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&Oslash;" withString:@"Ø"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		mytext = [mytext stringByReplacingOccurrencesOfString:@"&Aring" withString:@"Å"];
		mytext = [mytext stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

		
		
		
		textView.font=[UIFont fontWithName:@"Times New Roman" size:16];
		textView.text=mytext;		
		CGRect myframe1=CGRectMake(502, 89, 200, 128);
		Book*book1=[rowTwoSecond objectAtIndex:a];
		
		NSString*text2=book1.teaser;
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&aring" withString:@"å"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&oslash" withString:@"ø"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
	
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&aelig;" withString:@"æ"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&AElig;" withString:@"Æ"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&Oslash;" withString:@"Ø"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		text2 = [text2 stringByReplacingOccurrencesOfString:@"&Aring" withString:@"Å"];
		text2 = [text2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		
		
		
		
		UITextView*textViewtwo=[[UITextView alloc] initWithFrame:myframe1];
		textViewtwo.font=[UIFont fontWithName:@"Times New Roman" size:16];
        textViewtwo.text=text2;
		
		
		UIButton*headingButton=[UIButton buttonWithType:UIButtonTypeCustom];
		headingButton.frame=CGRectMake(16, 49, 300, 37);
		NSString*headingbuttontitle=book.title;
		headingbuttontitle = [headingbuttontitle stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		headingbuttontitle = [headingbuttontitle stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];

				
		
		headingButton.tag=J;

		[headingButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		[headingButton setTitle:headingbuttontitle forState:UIControlStateNormal];
		
		[headingButton addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		testButton3.tag=J;
		[testButton3 addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		headingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
		headingButton.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];

		UIButton*myImageButton=[UIButton buttonWithType:UIButtonTypeCustom];
		myImageButton.frame=CGRectMake(16, 85, 90, 127);
		NSString*thumb2=book.thumbimgurl;
		thumb2 = [thumb2 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		thumb2 = [thumb2 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		UIImage *image2 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb2]]];
		myImageButton.tag=J;
		[myImageButton setBackgroundImage:image2 forState:UIControlStateNormal];
		// myImageView.image=[UIImage imageNamed:@"thumb.jpg"];
		[myImageButton addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		[subView1 addSubview:myImageButton];

		
		
		
		
		J++;
		
		
		
		
		
		
		
		
		UIButton*headingButton1=[UIButton buttonWithType:UIButtonTypeCustom];
		headingButton1.frame=CGRectMake(407, 49, 300, 37);	
		[headingButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
		
		
		NSString*headingbutton1title=book1.title;
		headingbutton1title = [headingbutton1title stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		headingbutton1title = [headingbutton1title stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		
		
		
		
		
		
		
		
		UIButton*myImageButton1=[UIButton buttonWithType:UIButtonTypeCustom];
		myImageButton1.frame=CGRectMake(407, 85, 90, 127);
		NSString*thumb1=book1.thumbimgurl;
		thumb1 = [thumb1 stringByReplacingOccurrencesOfString:@"\n" withString:@""];
		thumb1 = [thumb1 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
		UIImage *image1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:thumb1]]];
		myImageButton1.tag=J;
		[myImageButton1 setBackgroundImage:image1 forState:UIControlStateNormal];
		// myImageView.image=[UIImage imageNamed:@"thumb.jpg"];
		[myImageButton1 addTarget:self action:@selector(tappedItemAtIndex:) forControlEvents:UIControlEventTouchUpInside];	
		
		
		
		testButton4.tag=J;
		
		[testButton4 addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];	
		
		
		[subView1 addSubview:myImageButton1];
		
		
				
		
		
		headingButton1.titleLabel.font = [UIFont boldSystemFontOfSize:20 ];
		headingButton1.tag=J;
		
		[headingButton1 setTitle:headingbutton1title forState:UIControlStateNormal];

		
		[headingButton1 addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];	

		
		headingButton1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
		
		
		
		
		
		
		[subView1 addSubview:headingButton];
		[subView1 addSubview:headingButton1];
		[subView1 addSubview:textView];
		[subView1 addSubview:textViewtwo];
		
		
		}
