Xcode 获取同一视图中的TableView选定行值
我有一个带有分段控件、文本字段和表视图的页面。用户写入/选择他想要的内容,然后点击一个按钮,该按钮将所有值传递给另一个视图(所述值用于执行搜索)。 这是传递值的函数的简化版本:Xcode 获取同一视图中的TableView选定行值,xcode,uitableview,Xcode,Uitableview,我有一个带有分段控件、文本字段和表视图的页面。用户写入/选择他想要的内容,然后点击一个按钮,该按钮将所有值传递给另一个视图(所述值用于执行搜索)。 这是传递值的函数的简化版本: -(IBAction) doTheSearch { [self dismissViewControllerAnimated:YES completion:nil]; // initialize the view who will perform the search NewSearchCont
-(IBAction) doTheSearch {
[self dismissViewControllerAnimated:YES completion:nil];
// initialize the view who will perform the search
NewSearchController *nsc = [[NewSearchController alloc] init];
// set values from one text field and one segmented control
nsc.testString = textfield.text;
NSString *temp = [NSString stringWithFormat:@"%d",segmentedcontrol.selectedSegmentIndex];
nsc.testCode = temp;
[self.navigationController pushViewController:nsc animated:YES];
}
是否可以像我对文本字段和分段控件的值所做的那样,使用相同的函数从表视图中选择哪些行
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
从上面的代码中可以得到indexPath
path.row
以获取所选的确切行
从上面的代码中可以得到indexPath
path.row
以获取所选的确切行 亲爱的约翰,首先感谢你的回复。也许我迷路了,但我试过了,结果出现了一个错误(tableView没有属性)。然后,如果我尝试初始化(in.h)和合成(in.m)一个名为“tableView”的属性,我到处都会收到警告消息说“tableView的本地声明隐藏实例变量”。亲爱的John,首先感谢您的回复。也许我迷路了,但我试过了,结果出现了一个错误(tableView没有属性)。然后,如果我尝试初始化(in.h)和合成(in.m)一个名为“tableView”的属性,我会得到警告消息,到处都是“tableView的本地声明隐藏实例变量”。