我有一个用下面的数据编写的表视图。它也有一个编程到页面上的工作搜索功能。我正在尝试使用“切换”系统来根据按下的单元格转换到特定的视图控制器。
- (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单元格中的对象执行分割方面遇到了困难。显然,目前segues依赖于indexPath.row,这对于可搜索表是无用的。(我知道segues目前只有在过滤数据时才起作用)。
任何建议都将不胜感激!
干杯
发布于 2013-02-07 01:16:07
您可以使用
-(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];
}
}在你的方法中。然后你可以从中得到你想要的任何东西。
发布于 2013-02-07 11:20:14
我想知道你为什么用“一”,“二”...作为标识符,为什么不使用您的smtArrays对象名作为标识符?如果你担心标识符被替换,你可以使用SSSOfCategory + name。这样你的代码就完美了,可读性也更好了。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Smt *smt = nil;
if (tableView == self.searchDisplayController.searchResultsTableView) {
smt = [filteredSmtsArry objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:smt.name sender:self];
}
}https://stackoverflow.com/questions/14733668
复制相似问题