1
在我的應用程序中,我在表格視圖中的每一行中都實現了單選按鈕。 問題是當我點擊第1行的單選按鈕時,即第5行的單選按鈕被選中。單擊單選按鈕時
我需要選擇我點擊的按鈕。這是我所做的代碼。
在此先感謝。
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIImageView *backGroundImageView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"History_strip_bg1.png"]];
[cell.contentView addSubview:backGroundImageView];
[backGroundImageView release];
cell.accessoryView=[[ UIImageView alloc ]initWithImage:[UIImage imageNamed:@"arrow2.png"]];
if(doneBtnFlag)
{
radioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[radioBtn setImage:[UIImage imageNamed:@"radio_button_1.png"] forState:UIControlStateNormal];
[radioBtn setImage:[UIImage imageNamed:@"radio_button_selected.png"] forState:UIControlStateSelected];
[radioBtn setFrame:CGRectMake(2, 17, 25, 25)];
[cell.contentView addSubview:radioBtn];
[radioBtn addTarget:self action:@selector(radioButtonClicked:event:) forControlEvents:UIControlEventTouchUpInside];
radioBtn.tag = 1;
}
btn=(UIButton*)[cell.contentView viewWithTag:1];
}
return cell;
}
- (IBAction)radioButtonClicked:(id)sender event : (id)event
{
btn.selected = YES;
rightBtn.enabled =YES;
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:contactsTblView];
NSIndexPath *indexPath = [contactsTblView indexPathForRowAtPoint: currentTouchPosition];
NSLog(@"indexPath %@",indexPath);
}