我创建了从 UIViewController 类派生的 MasterViewController 的两个实例
_masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController_iPhone" bundle:nil];
// second instance with same class and duplicate nib view
_favItemMasterVC = [[MasterViewController alloc] initWithNibName:@"favMasterViewController_iPhone" bundle:nil];
MasterViewController_iPhone 和 favMasterViewController_iPhone View 都是相同的。
现在我想检查当前选择了哪个 UIViewController(例如:在标签栏上)。
我怎样才能找到两个对象之间的区别?
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if ([viewController isKindOfClass:[_favItemListMasterVC class]]
{ // it is always called in both cases}
isMemberOfClass://也不工作
如何检查差异?
最佳答案
不确定我是否理解您在做什么,但如果 _favItemListMasterVC 和 _masterViewController 指向添加到 UITabBar 的相同 VC,您可以简单地比较指针来检查它
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (viewController == _favItemListMasterVC)
{
//the visible view controller is _favItemListMasterVC
}
关于iphone - 比较同一 UIViewController 类的实例或对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13415677/