Clicking Event in UITableView Clicking Event in UITableView ios ios

Clicking Event in UITableView


Declare an int variable globally -

int rowNo;

Then assign value to it in didSelectRowAtIndexPath: method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     rowNo = indexPath.row; }

Now you have the indexNo. of selected row.

-(IBAction)doDownload:(id)sender{    //Now compare this variable with 0 because first row index is 0.    if(rowNo == 0)    {         [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.google.com"]];    }}


You have to use the function didSelectRowAtIndexPath method of tableView.

in that method you save the selected row tag or whatever you want to save.and in the button action check the value of the saved entity and do anything.


Use the datasource function of UITableView which is

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{}

which indexPath.row is each row's index.