开发者

Compare self.parentViewController to a given UIViewController

Is it possible? That is, can I do something like this, which doesn't work...

if (self.parentViewController == CustomViewController) {
    // do something
} else {
    // do something else
}

...to make, for example, a Settings panel look more like either of its possible parent controllers? (Example again, if the menu is soft and light but the gameplay is kinda dark, it'd be convenient to say "if your parent is A look lik开发者_StackOverflow中文版e this, but if your parent is B, look like this")

If it definitely can't be done, or if comparing the parentViewController to something else is dangerous/messy, I'll just set a flag fromView and code according to that.


You could go with if([self.parentViewController isKindOfClass:[CustomViewController class]])


self.parentViewController returns NavigationController so it doesn't work, so I found other way, this worked for me:

unsigned long currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];

//previous view controller
UIViewController *view = (UIViewController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex - 1];

if([view isKindOfClass:[CustomViewController class]])
{
    [self runSomething];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜