我有tableView with detailDisclosure按钮它工作正常,但我想给详细信息披露按钮的标题,所以我想我需要添加自定义UIButton for detailDisclosure是否可以这样做,我想这样做而不使用自定义单元格。< / p>
如果我想提供图像,它可以正常工作,但我怎么可以给这个按钮标题,如评论。
cell.accessoryView = [[ UIImageView alloc ]
initWithImage:[UIImage imageNamed:@"loginN.png" ]];
答案 0 :(得分:0)
试试这个..
UIButton *btn = [[[UIButton alloc]init]autoerelease];
btn .frame = CGRectMake(210.0, 0.0, 90, 25);
btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"loginN.png"] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClickHandler:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubView: btn];
并在btnClickHandler中执行此操作以获取indexPath
- (void)btnClickHandler :(UIButton *)button {
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
//Get your data source object from indexPath.row.
}
答案 1 :(得分:0)
为什么不像设置图像那样将a按钮设置为附件视图.. ??
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0.0, 0.0, 80.0, 80.0);//Set the frame u need for the view
//Customize the button
[button setTitle:@"title" forState:UIControlStateNormal];
//And set it as accessory view
cell.accessoryView = button;
结果如下......