几天来我遇到了一个问题。问题是我有一个包含多个自定义表格单元格的表格,每个单元格都有多个按钮。但我总是将标签值设为零。下面是我的代码
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CuatomCell_Contacts *cell = (CuatomCell_Contacts *) [tableView dequeueReusableCellWithIdentifier:@"cellA"];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CuatomCell_Contacts" owner:Nil options:nil];
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (CuatomCell_Contacts *) currentObject;
break;
}
}
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
IstructContacts *ObjIstructContacts = nil;
if (table == self.searchDisplayController.searchResultsTableView)
{
ObjIstructContacts = [self.filteredListContent objectAtIndex:indexPath.row];
}
else
{
ObjIstructContacts = [self.sectionedListContent objectAtIndexPath:indexPath];
}
cell.m_CtrlLblName.text = ObjIstructContacts.m_strName;
//cell.m_CtrlLblContact_Id.text=ObjIstructContacts.m_strContact_Id;
NSLog(@"%@",ObjIstructContacts.m_strImageUrl);
if ([ObjIstructContacts.m_strImageUrl isEqualToString:@"No_image"])
{
cell.m_CtrlImgImage.image=[UIImage imageNamed:@"Person_Dumy.jpeg"];
}
else
{
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: ObjIstructContacts.m_strImageUrl]];
cell.m_CtrlImgImage.image=[UIImage imageWithData: imageData];
}
cell.M_CtrlBtnChat.tag=indexPath.row;
[cell.M_CtrlBtnChat addTarget:self action:@selector(MoveToNextView:) forControlEvents:UIControlEventTouchUpInside];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(MoveToNextView:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Custom Action" forState:UIControlStateNormal];
button.frame = CGRectMake(150.0f, 5.0f, 150.0f, 30.0f);
button.tag=indexPath.row;
[cell.contentView addSubview:button];
return cell;
}
-(void)MoveToNextView:(id)sender
{
UIButton *button = (UIButton *)sender;
NSLog(@"Tag Value = %d",button.tag);
}
标记值始终返回零。在静态和动态按钮操作中。