Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

ios - iPhone SDK: Opening a cell with a dedicated button, not by cell tapping

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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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. 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...