iPhone SDK:使用专用按钮打开单元格,而不是通过单元格点击打开 [英] iPhone SDK: Opening a cell with a dedicated button, not by cell tapping

查看:98
本文介绍了iPhone SDK:使用专用按钮打开单元格,而不是通过单元格点击打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a simple TableView containing several cells. Normally, I switch to selected cell details by tapping this cell. But what if I need a dedicated button for every cell? I've seen "Table View Cell" properties in Interface Builder, it has what I need, but it can't be added to existing cells.

如何正确添加对于标准TableView的每个单元格的这种按钮?

How to properly add this kind of button to every cell of standard TableView?

推荐答案

我在我正在处理的应用程序中执行类似的操作。我有一个单元格,上面有一个按钮,我需要知道在哪个单元格中按了哪个按钮。我是这样做的..

I do something similar in an app I am working on right now. I have a cell that has a button on it, and I need to know which button was pushed in which cell. I do that like this..

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

I add my button to each cell..

// 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];

用于确定选择了哪个单元格的按钮的方法,然后推送另一个视图控制器使用所选按钮的信息...

The method used to determine which "button" in which cell was selected, I then push another view controller with the information of the selected button...

// 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];
}

这是按钮在每个单元格上的样子。
希望这会有所帮助!

This is what the button looks like on each cell. Hope this helps!

P.S。点击CELL,会推送另一个视图控制器,但点击Buy Tickets按钮会推送另一个视图控制器。

P.S. Tapping on the CELL, would push another view controller, but tapping on "Buy Tickets" button pushes a different one.

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

这篇关于iPhone SDK:使用专用按钮打开单元格,而不是通过单元格点击打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆