[英]How to get selected index in tableview
我正在使用表格视图。 在下面的方法中,我想将appdelegate.page
的值设置为表行索引的值。
如果选择了第一行,则appdelegate.page = 1
;如果选择了第二行,则appdelegate.page = 2
...那么,我应该用代码中的索引路径替换什么,以便获得所选的行索引?
这是我的代码:
- (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];
}
您将放置indexPath.row或indexPath.item。
indexPath.item是首选。
- (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];
}
使用indexPath.row
获取选定的行值,该值将在应用程序委托中设置页面属性。
在表格的单元格中创建一个按钮,并使用indexpath.row将其设置为Tag
然后使用:
-(IBAction)YourButton_TouchUpInside:(id)sender
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.