2013-03-12 102 views
0

我想提上Navigation ItemUISegmentedControl但它崩潰我的Xcode ..我只是簡單地添加在界面生成器文件中的UISegmentedControl(IB)文件,然後在viewDisAppearUISegmentedControl``崩潰的Xcode

.H

IBOutlet UISegmentedControl *segmentedControl; 

.M

self.navigationItem.titleView=segmentedControl; 

這只是我崩潰的xcode與錯誤

2013-03-12 17:38:56.343 Magazine[4728:1dc03] *** Assertion failure in -[UINavigationBar layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 
2013-03-12 17:38:56.344 Magazine[4728:1dc03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UINavigationBar's implementation of -layoutSubviews needs to call super.' 
*** First throw call stack: 
(0x2854012 0x1ee9e7e 0x2853e78 0x197ff35 0xe819ef 0x1efd6b0 0x7d1fc0 0x7c633c 0x7c6150 0x7440bc 0x745227 0x7458e2 0x281cafe 0x281ca3d 0x27fa7c2 0x27f9f44 0x27f9e1b 0x2d1c7e3 0x2d1c668 0xe3165c 0x2de5 0x2ce5) 

的libC++ abi.dylib:終止叫做拋出異常

爲什麼這個錯誤是未來

+0

你在哪裏把分割控制在界面生成器?難道你不能直接在nib文件中使分割控件成爲標題視圖嗎? – architectpianist 2013-03-12 12:19:52

+0

通常在視圖中...但如何使直接在筆尖文件中的標題視圖的分段控制 – Christien 2013-03-12 12:22:13

+1

爲什麼你把段放在XIB中,然後在代碼中給出?相反,你可以分配init的segmentedControl通過代碼,然後嘗試.. – 2013-03-12 12:22:43

回答

2
UISegmentedControl * seg1 = [[UISegmentedControl alloc] 
    initWithItems:[NSArray arrayWithObjects:@"von mir", @"alle", nil]]; 
[seg1 setSegmentedControlStyle:UISegmentedControlStyleBar]; 
self.navigationItem.titleView = seg1;