0

我有带有 detailDisclosure 按钮的 tableView,它工作正常,但我想为详细信息披露按钮提供标题,所以我认为我需要为 detailDisclosure 添加自定义 UIButton 是否可以像我想做的那样在不使用自定义单元格的情况下执行此操作。

如果我想提供图像,它可以正常工作,但我如何为这个按钮提供标题,如评论。

  cell.accessoryView = [[ UIImageView alloc ] 
                            initWithImage:[UIImage imageNamed:@"loginN.png" ]];
4

2 回答 2

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.
}
于 2013-07-11T05:33:11.800 回答
0

为什么不将按钮设置为附件视图,就像您尝试设置图像一样..??

    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;

这是结果... 在此处输入图像描述

于 2013-07-11T06:00:01.047 回答