Reputation:
I am trying to make an app that the user will press a cell and the cell will function as a button, now how do I make the cell function as a button and do an action or how do I know which cell is being pressed?
Upvotes: 1
Views: 114
Reputation: 3586
If I understood your question correctly, you simply want to run some code when a user touches a cell.
The UITableViewDelegate has a method called tableView:didSelectRowAtIndexPath:
(UITableViewDelegate tableView:didSelectRowAtIndexPath:
)
Just implement that and you can do what you want in there.
Upvotes: 0
Reputation: 434
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
this method gets called when the user taps a cell. indexPath.section
and indexPath.row
are your cell section and row indexs.
http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewDelegate_Protocol/Reference/Reference.html
Upvotes: 0
Reputation: 40211
You implement the UITableViewDelegate
method tableView:didSelectRowAtIndexPath:
.
That method will be called whenever the user taps any of the cells. If the passed indexPath
is the index path of your button cell, then you do whatever should happen.
Upvotes: 1
Reputation: 4085
Please read the document but basically when you set the delegate of the tableviewcontroller it calls this method when clicked:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
The indexpath holds the section and the row. If you are using only one section then indexPath.row
will return the index of the cell that was clicked.
Upvotes: 2
Reputation: 1852
Read Apple's documentation on UITableViewDelegate
And you will find tableView:didDeselectRowAtIndexPath:
Upvotes: 0