在UITableView中加载动态数据。我在RadioButtons(groupButtons)
和btnPaul
中有2 btnAdam
UITableView
和label(lblCheckStatus)
标题为Paul和Adam。如果[cell.btnPaul setSelected:YES];
btnPaul.titlelebel.text
应该标记,即保罗和[cell.btnPaul setSelected:NO];
标签在UITableView
中应为空。我已尝试过followign代码,但无法获得正确的响应获取null值。 TIA
// cellForRowAtIndexPath:
NSMutableDictionary* respDict = [respnseArray objectAtIndex:indexPath.row];
NSString *str = [respDict objectForKey:@"Name"];
if ([str isEqualToString:@"Paul"]) {
[cell.btnPaul setSelected:YES];
} else {
[cell.btnAdam setSelected:YES];
}
cell.btnPaul.tag = +indexPath.row;
[cell.btnPaul addTarget:self action:@selector(btnCheckClicked:) forControlEvents:UIControlEventTouchUpInside];
cell.btnPaul.tag = +indexPath.row;
[cell.btnPaul addTarget:self action:@selector(btnCheckClicked:) forControlEvents:UIControlEventTouchUpInside];
// RadioButton Checked
- (IBAction)btnCheckClicked:(RadioButton *)sender {
UIButton *btn = (UIButton *)sender;
NSUInteger tag = btn.tag;
static NSString *CellIdentifier = @"Cell";
FriendsCell *cell = (FriendsCell *) [_btlFriends dequeueReusableCellWithIdentifier:CellIdentifier];
cell.lblCheckStatus.text = sender.titleLabel.text;
NSLog(@"%@",cell.lblCheckStatus.text);
}
答案 0 :(得分:0)
首先,在设置单选按钮标记时删除+
。
cell.btnPaul.tag = indexPath.row;
[cell.btnPaul addTarget:self action:@selector(btnCheckClicked:) forControlEvents:UIControlEventTouchUpInside];
然后使用标记获取indexPath。当您使用indexPath时,您可以访问单元格,也可以访问单元格组件。希望这会对你有所帮助。
- (IBAction)btnCheckClicked:(RadioButton *)sender {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
FriendsCell *cell = [_btlFriends cellForRowAtIndexPath:indexPath];
cell.lblCheckStatus.text = cell.btnPaul.titleLabel.text;
NSLog(@"%@",cell.lblCheckStatus.text);
}