If 语句基于之前的视图控制器是什么 [英] If statement based on whatever the previous view controller was
本文介绍了If 语句基于之前的视图控制器是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我目前所做的:
- (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
部分只是为了向您展示我想尝试做的事情).
It looks messy, that's why im trying to fix it up (that previousViewController
part is just made up to show you what I want to try to do).
我想说的是:如果你是通过这个 segue 或从那个名为 suchandsuch
的视图控制器到达这个视图的,那么执行这个 segue 或那个 segue.有没有办法做到这一点?
What im trying to say is: If how you got to this view was via this segue, or from that view controller with the name suchandsuch
, then preform this segue or that segue. Is there a way I can do that?
推荐答案
可以从 Navigation Controller 中查看堆栈的上一个 ViewController.
You can check the previous ViewController of the stack from the Navigation Controller.
- (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];
}
这篇关于If 语句基于之前的视图控制器是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文