开发者

How to get selected index in tableview

开发者 https://www.devze.com 2023-01-17 10:53 出处:网络
I am using a table view. In the below method, I want to set the value of appdelegate.page to the value of table row index.

I am using a table view. In the below method, I want to set the value of appdelegate.page to the value of table row index.

if row one is selected, then appdelegate.page = 1, if row开发者_如何学JAVA two is selected, then appdelegate.page = 2... So what should I replace with index path in my code so that I will get the selected row index?

Here is my code:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  appDelegate = [[UIApplication sharedApplication] delegate];
  appDelegate.page = indexPath;//////what should i put here instead of indexpath    
  SecondViewController *svc = [[[SecondViewController alloc] init] autorelease];
  svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
  [self presentModalViewController:svc animated:YES];       
}


Create a Button in Cell of Table and set it's Tag with indexpath.row

Then Use:

-(IBAction)YourButton_TouchUpInside:(id)sender
{
}


You would put indexPath.row or indexPath.item.

indexPath.item is preferred.


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
appDelegate = [[UIApplication sharedApplication] delegate];
appDelegate.page = indexPath.row;

SecondViewController *svc = [[[SecondViewController alloc] init] autorelease];
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[self presentModalViewController:svc animated:YES];

}

Use indexPath.row to get selected row value which will set up page property in app delegate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号