iphone - 比较同一 UIViewController 类的实例或对象

标签 iphone ios ipad uiviewcontroller uitabbarcontroller

我创建了从 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/

相关文章:

objective-c - 在 iOS 8.2 上播放短音频的最佳方法

objective-c - nspredicate 转义 url

iphone - CABasicAnimation 键

iphone - UIImagePickerController CameraDevice 每隔一段时间就会选择错误的设备(使用 ARC)

iphone - 无法弄清楚如何发布在 iPhone 上生成的公钥

iphone - Apple 批准应用程序

ios - 一个 View 中的多个 MPMoviePlayerController

ipad - 如何从UITableView删除页眉和页脚空间?

ios - UIScrollView 不能在 ipad 中工作

html - 无法阻止初始比例 = 1 的 iPhone 缩放