Iphone 如何使用xcode5在iOS7GM中添加自定义uitabar
您好,我是iOS中的begginer,我创建了自定义tabbar并添加了UIbar按钮项,这些项在iOS 6中正常工作,但在iOS 7 GM和Xcode 5中它显示了问题。。。。。 这是我自定义选项卡栏的代码Iphone 如何使用xcode5在iOS7GM中添加自定义uitabar,iphone,objective-c,ios7,Iphone,Objective C,Ios7,您好,我是iOS中的begginer,我创建了自定义tabbar并添加了UIbar按钮项,这些项在iOS 6中正常工作,但在iOS 7 GM和Xcode 5中它显示了问题。。。。。 这是我自定义选项卡栏的代码 TabBar=[[UITabBar alloc]initWithFrame:CGRectMake(0, 480, 320, 80)]; TabBar.autoresizingMask =UIViewContentModeTopRight | UIViewAutoresizingFlexi
TabBar=[[UITabBar alloc]initWithFrame:CGRectMake(0, 480, 320, 80)];
TabBar.autoresizingMask =UIViewContentModeTopRight | UIViewAutoresizingFlexibleWidth;
TabBar.tintColor=[UIColor blackColor];
UIButton *btn1=[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 20, 20)];
[btn1 setTitle:@"Charge Details" forState:UIControlStateNormal];
btn1.titleLabel.font=[UIFont boldSystemFontOfSize:10.0];
[btn1 addTarget:self action:@selector(ChargeDetails) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button1 = [[UIBarButtonItem alloc]initWithCustomView:btn1];
UIButton *btn2=[[UIButton alloc]initWithFrame:CGRectMake(0,0,40,40)];
btn2.titleLabel.font=[UIFont boldSystemFontOfSize:10.0];
[btn2 setTitle:@"View Contact Details" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(ViewContactDetails) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc]initWithCustomView:btn2];
TabBar.items=[NSArray arrayWithObjects:button1,button2,nil];
[self.view addSubview:TabBar];
此代码在iOS 6中成功运行,但在iOS 7 GM中我有问题..实际上自定义Tabbar加载项视图成功,但当我们添加barbutton项时,此显示错误…在此行中
TabBar.items=[NSArray arrayWithObjects:button1,button2,nil];
这是一个错误
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem _updateViewForIdiom:positionItems:]: unrecognized selector sent to instance 0xbd3c6c0'
*** First throw call stack:
(
0 CoreFoundation 0x04b9a5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x018b58b6 objc_exception_throw + 44
2 CoreFoundation 0x04c37903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x04b8a90b ___forwarding___ + 1019
4 CoreFoundation 0x04b8a4ee _CF_forwarding_prep_0 + 14
5 UIKit 0x006caefa -[UITabBar setItems:animated:] + 1218
6 UIKit 0x006c9d9c -[UITabBar setItems:] + 48
7 HISWebService 0x00021ee6 -[PatientLabDetailsViewController viewDidLoad] + 4566
8 UIKit 0x0052e9a8 -[UIViewController loadViewIfRequired] + 696
9 UIKit 0x0052ec44 -[UIViewController view] + 35
10 UIKit 0x00548a72 -[UINavigationController _startCustomTransition:] + 778
11 UIKit 0x00555757 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
12 UIKit 0x00556349 -[UINavigationController __viewWillLayoutSubviews] + 57
13 UIKit 0x0068f39d -[UILayoutContainerView layoutSubviews] + 213
14 UIKit 0x00485dd7 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
15 libobjc.A.dylib 0x018c781f -[NSObject performSelector:withObject:] + 70
16 QuartzCore 0x03e1172a -[CALayer layoutSublayers] + 148
17 QuartzCore 0x03e05514 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
18 QuartzCore 0x03e05380 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
19 QuartzCore 0x03d6d156 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
20 QuartzCore 0x03d6e4e1 _ZN2CA11Transaction6commitEv + 393
21 QuartzCore 0x03d6ebb4 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
22 CoreFoundation 0x04b6253e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
23 CoreFoundation 0x04b6248f __CFRunLoopDoObservers + 399
24 CoreFoundation 0x04b403b4 __CFRunLoopRun + 1076
25 CoreFoundation 0x04b3fb33 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x04b3f94b CFRunLoopRunInMode + 123
27 GraphicsServices 0x01ab59d7 GSEventRunModal + 192
28 GraphicsServices 0x01ab57fe GSEventRun + 104
29 UIKit 0x0041b94b UIApplicationMain + 1225
30 HISWebService 0x0001f5fd main + 141
31 libdyld.dylib 0x051be725 start + 0
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
请解决我的问题,如何在iOS 7 GM中的UITabbar上添加自定义按钮。。。。
提前感谢 来自苹果的Tabbar文档: 选项卡栏是一个控件,通常出现在控件的底部 选项卡栏控制器上下文中的屏幕,用于向用户提供 轻触一下,以模式访问应用程序中的一组视图。每个按钮在一个 选项卡栏称为选项卡栏项,是 Uitabritem类。如果您想给用户一个 每个执行操作的按钮都使用UIToolbar对象 UITabBar类支持用户通过以下方式自定义选项卡栏: 重新排序、删除和向栏中添加项目。你可以使用标签 bar委托以增强此行为 使用uitabaritem类创建项目和setItems:animated: 方法将它们添加到选项卡栏。具有动画的所有方法: 参数允许您选择设置显示更改的动画。使用 selectedItem属性以访问当前项 您正在选项卡栏中使用UIBarButtonims。如果要使用选项卡栏,请使用UITabBarItems
但是,看到您正在向按钮添加操作,您应该使用工具栏,而不是选项卡栏。如果你做了这些改变,它应该工作得很好 来自苹果的Tabbar文档: 选项卡栏是一个控件,通常出现在控件的底部 选项卡栏控制器上下文中的屏幕,用于向用户提供 轻触一下,以模式访问应用程序中的一组视图。每个按钮在一个 选项卡栏称为选项卡栏项,是 Uitabritem类。如果您想给用户一个 每个执行操作的按钮都使用UIToolbar对象 UITabBar类支持用户通过以下方式自定义选项卡栏: 重新排序、删除和向栏中添加项目。你可以使用标签 bar委托以增强此行为 使用uitabaritem类创建项目和setItems:animated: 方法将它们添加到选项卡栏。具有动画的所有方法: 参数允许您选择设置显示更改的动画。使用 selectedItem属性以访问当前项 您正在选项卡栏中使用UIBarButtonims。如果要使用选项卡栏,请使用UITabBarItems 但是,看到您正在向按钮添加操作,您应该使用工具栏,而不是选项卡栏。如果你做了这些改变,它应该工作得很好