如何解决如何在iphone sdk中设置类似的按钮标签和单元标签
|| 我有一个包含标签和按钮的表。在该按钮上,我生成了下拉列表。我想将单元格标签和按钮标签设置为相似。根据我的说法,我必须保持自己的功能。供您参考,下面的图片会给您带来帮助 这是我在CellForRowAtIndexPath中的代码:-NSString * s; Var = 0;if(indexPath.row<=2)
{
btn_click.tag=indexPath.row;
s =[dict valueForKey:[NSString stringWithFormat:@\"%d\",indexPath.row]];
}
else
{
if (indexPath.row%3==0)
{
Var=(NSInteger)(indexPath.row/3);
}
else
{
Var=Var+1;
}
if(indexPath.row%3==0 && Var==1)
{
btn_click.tag=indexPath.row;
s =[dict valueForKey:[NSString stringWithFormat:@\"%d\",indexPath.row]];
}
else
{
if (Var>1)
{
Var=1;
}
btn_click.tag=indexPath.row-Var;
s =[dict valueForKey:[NSString stringWithFormat:@\"%d\",indexPath.row-Var]];
}
}
NSLog(@\"CELLTAGTag%d\",btn_click.tag);
}
感谢和问候,
普里扬卡。
解决方法
将按钮的标签设为
indexPath.row
。因此,您可以使用行值(也就是UIButton
的tag
)来获得单元格
yourButton.tag = indexPath.row
,如果要为在单元格行号上展开的cellView和buttonView赋予相同的标签号,可以执行以下操作:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @\"CustomTableCell\";
static NSString *CellNib = @\"UserCustomTableCell\";
UserCustomTableCell *cell = (UserCustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CellNib owner:self options:nil];
cell = (UserCustomTableCell *)[nib objectAtIndex:0];
}
cell.myButton.tag = [indexPath.row];
cell.tag = [indexPath.row];
return cell;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。