小编use*_*219的帖子

IOS5中的UITabbarcontroller抛出UIViewControllerHierarchyInconsistency异常

我有UITabbarcontroller的以下代码:

NSMutableArray *arr = [[NSMutableArray alloc] init];
tabBarController = [[UITabBarController alloc] init];

FirstViewController *firstview = [[FirstViewController alloc] init];
[tabBarControllerViews addObject:firstview];
[firstview release];

 SecondViewController *secondview = [[SecondViewController alloc] init];
[tabBarControllerViews addObject:secondview];
[secondview release];

[tabBarController setViewControllers:arr animated:YES];
[arr release];

self.view = tabBarController.view;
Run Code Online (Sandbox Code Playgroud)

此代码在IOS4上运行良好.我在IOS5测试版上尝试了它,并在点击UITabbarItem时出现以下错误:

*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency',
reason: 'child view controller:<FirstViewController: 0x6e03be0> should have parent view
controller:<MainViewController: 0x6816d20> but actual parent is:<UITabBarController: 0x6b0c110>'
Run Code Online (Sandbox Code Playgroud)

objective-c uitabbarcontroller ios5

15
推荐指数
3
解决办法
7647
查看次数

如何在Objective-C中使用operator <或>比较对象?

如何在Objective-C中比较自定义类的两个对象?我试着重载

- (NSComparisonResult)compare:(id)other;

方法.如果我手动调用该方法,这非常有效

if ([obj1 compare:obj2] == NSOrderedDescending) {  
    // do something  
}  
Run Code Online (Sandbox Code Playgroud)

我有什么方法可以这样做吗?

if (obj1 > obj2) {
    // do something
}
Run Code Online (Sandbox Code Playgroud)

还是有另一种方法需要重载?

compare object objective-c

2
推荐指数
1
解决办法
649
查看次数

标签 统计

objective-c ×2

compare ×1

ios5 ×1

object ×1

uitabbarcontroller ×1