我正在检查我的tabBar中的第二个标签toViewController
是否属于MatchCenterViewController
类,但是else
语句正在运行,这告诉我它不属于那个班级。
我很肯定该标签中的UIViewController
与MatchCenterViewController
相关联,那么还有什么可能导致此if
语句不起作用?
NSLog(@"numberOfMatches is 1");
UIViewController *toViewController = [self.tabBarController viewControllers][1];
NSLog(@"toViewController: %@", toViewController);
if ([toViewController isKindOfClass:[MatchCenterViewController class]]) {
NSLog(@"2nd matchcenter if statement works");
MatchCenterViewController *matchViewController = (MatchCenterViewController *)toViewController;
matchViewController.didAddNewItem = YES;
NSLog(@"alright they're set, time to switch");
}
else {
NSLog(@"toViewController is not MatchCenterViewController");
}
[self.tabBarController setSelectedIndex:1];
答案 0 :(得分:1)
您可以添加NSLog(@"toViewController is of class: %@", NSStringFromClass([toViewController class]);
并查看实际的视图控制器类。
如果didAddNewItem
是只有 MatchCenterViewController 的属性,您可以尝试这种方式:
if ([toViewController respondsToSelector:@selector(setDidAddNewItem:)]) {
// this is MatchCenterViewController
} else {
// this is not MatchCenterViewController
}