我有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中比较自定义类的两个对象?我试着重载
- (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)
还是有另一种方法需要重载?