这是我到目前为止所做的:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (preivousViewController isEqualToString:@"...")
{
if ([self.filteredArray count] == 0)
self.person = self.users[indexPath.row];
else
self.person = self.filteredArray[indexPath.row];
self.mugshot = cell.imageView.image;
[self performSegueWithIdentifier:@"SelectPerson" sender:self];
} else {
if ([self.filteredArray count] == 0)
self.person = self.users[indexPath.row];
else
self.person = self.filteredArray[indexPath.row];
self.mugshot = cell.imageView.image;
[self performSegueWithIdentifier:@"selectVisitee" sender:self];
}
}
它看起来很乱,这就是为什么我试图解决它(previousViewController
部分只是为了向你展示我想要尝试做的事情。)
我想说的是:如果你通过这个segue,或者从名为suchandsuch
的视图控制器获得这个视图,那么就预先形成这个segue或者segue。我有办法做到吗?
答案 0 :(得分:1)
您可以从导航控制器中检查堆栈的上一个ViewController。
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ([self.filteredArray count] == 0)
self.person = self.users[indexPath.row];
else
self.person = self.filteredArray[indexPath.row];
self.mugshot = cell.imageView.image;
//Not the viewcontroller name string. Use the ViewController class name
if ([self backViewController] == YOURVIEWCONTROLLER)
{
[self performSegueWithIdentifier:@"SelectPerson" sender:self];
} else {
[self performSegueWithIdentifier:@"selectVisitee" sender:self];
}
}
使用以下方法,
- (UIViewController *)backViewController
{
NSInteger numberOfViewControllers = self.navigationController.viewControllers.count;
if (numberOfViewControllers < 2)
return nil;
else
return [self.navigationController.viewControllers objectAtIndex:numberOfViewControllers - 2];
}