我有一个用下面的数据编程的 TableView 。它还在页面上编程了一个有效的搜索功能。我正在尝试使用“切换”系统根据按下的单元格转移到特定的 View Controller 。
- (void)viewDidLoad
{
[super viewDidLoad];
smtArray = [[NSArray alloc] initWithObjects:
[Smt SSSOfCategory:@"P" name:@"HW"],
[Smt SSSOfCategory:@"P" name:@"WI"],
[Smt SSSOfCategory:@"P" name:@"WC"],
[Smt SSSOfCategory:@"P" name:@"C"],nil];
//搜索功能代码
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Smt *smt = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
smt = [filteredSmtsArry objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
[self performSegueWithIdentifier:@"One" sender:self];
break;
case 1:
[self performSegueWithIdentifier:@"Two" sender:self];
break;
default:
break;
}
}
}
目前,我对如何根据 tableview 单元格中的对象执行 segue 感到困惑。显然,目前 segues 依赖于 indexPath.row,这对于可搜索的表是无用的。 (我知道 segue 目前仅在数据被过滤后才有效)。
如有任何建议,我们将不胜感激!
干杯
最佳答案
你可以使用
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == self.searchDisplayController.searchResultsTableView) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *content = selectedCell.textLabel.text;
if ([content isEqualToString:"One"]) [self performSegueWithIdentifier:@"One" sender:self];
else if ([content isEqualToString:"Two"]) [self performSegueWithIdentifier:@"Two" sender:self];
}
}
在你的方法中。然后你可以从中得到任何你想要的东西。
关于ios - 如何在搜索栏中使用 switch 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14733668/