ios - iPhone SDK : Opening a cell with a dedicated button, 不是通过细胞敲击

标签 ios iphone tableview cell

我有一个包含多个单元格的简单 TableView。通常,我通过点击此单元格来切换到选定的单元格详细信息。但是,如果我需要为每个单元格设置一个专用按钮怎么办?我在 Interface Builder 中看到了“Table View Cell”属性,它有我需要的东西,但它不能添加到现有的单元格中。

如何正确地将这种按钮添加到标准 TableView 的每个单元格中?

最佳答案

我在我现在正在开发的应用程序中做了类似的事情。我有一个单元格,上面有一个按钮,我需要知道在哪个单元格中按下了哪个按钮。我是这样做的。。

我将按钮添加到每个单元格..

// add buy button to each cell
UIImage *image;
buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
image = [UIImage imageNamed:@"buy.png"];
[buyButton setBackgroundImage:image forState:UIControlStateNormal];
buyButton.frame = CGRectMake(220, 35, 96, 34);
[buyButton setTag:cellIndex];
[buyButton addTarget:self action:@selector(buyTickets:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:buyButton];

用于确定在哪个单元格中选择了哪个“按钮”的方法,然后我使用所选按钮的信息推送另一个 View Controller ......
// buy tickets button pressed from main table view 
- (void) buyTickets:(id)sender{


    ResultViewController *vc = [[ResultViewController alloc] init];
    vc.buyMovieID = [sender tag]; // "sender tag" is the cell id the button is located in
    [[super navigationController] pushViewController:vc animated:YES];
    [vc release];
}

这是每个单元格上按钮的外观。
希望这可以帮助!

附言点击 CELL 会推送另一个 View Controller ,但点击“购买门票”按钮会推送另一个 View Controller 。

alt text http://luistovar.com/ultratableview.jpg

关于ios - iPhone SDK : Opening a cell with a dedicated button, 不是通过细胞敲击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3416174/

相关文章:

ios - Storyboard View 调整大小问题

iphone - 如何在下载之前获取文档大小

ios - 删除单元格之前提醒 Controller Swift Xcode

uitableview - 如何快速获取所选行的textLabel?

JavaFX - 将列 id/order 放入列表/数组中

ios - 为什么括号会在 objective-c 中搞乱这个数学?

objective-c - 将 pdf 页面保存在多页数组中

iphone - 子类化 UIWindow

ios - 为 iPhone 开发 8085 模拟器的指南

iphone - viewWithTag 故障。