2010-01-01 23 views
15

Tôi đã tạo một UISegmentedControl và đã gắn thành công nó vào navigationItem.tableView của mình.UISegmentedControl, UIToolbar và UINavigationItem

Nhưng khi tôi cố gắng gắn nó vào thanh UIToolbar, nó sẽ thổi lên.

Tôi chắc chắn rằng tôi đã nhìn thấy UISegementedControls trên thanh công cụ trước đây - nhưng dường như không thể làm cho nó hoạt động. Suy nghĩ?

// works 
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil]; 
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems]; 
self.navigationItem.titleView = statusSegments_; 

// doesn't work 
NSArray *statusItems = [[NSArray alloc] initWithObjects:@"one", @"two", nil]; 
statusSegments_ = [[UISegmentedControl alloc] initWithItems:statusItems]; 
NSArray *toolbarItems = [[NSArray alloc] initWithObjects:statusSegments_, nil]; 
self.toolbarItems = toolbarItems; 
[toolbarItems release]; 
[Session started at 2010-01-01 13:40:35 -0600.] 
2010-01-01 13:40:35.182 TimeSheet[15382:20b] *** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0 
2010-01-01 13:40:35.183 TimeSheet[15382:20b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UISegmentedControl view]: unrecognized selector sent to instance 0x3f5c3e0' 
2010-01-01 13:40:35.184 TimeSheet[15382:20b] Stack: (
    10847323, 
    2479902267, 
    11229243, 
    10798710, 
    10651330, 
    24428622, 
    24429410, 
    24133352, 
    24133878, 
    11379, 
    24149733, 
    24130330, 
    24151483, 
    24129979, 
    23770, 
    23906970, 
    23890136, 
    2838970, 
    10631872, 
    10628168, 
    960429, 
    960626, 
    23633923 
)

Trả lời

34

Bạn cần phải quấn cái nhìn kiểm soát phân đoạn trong một UIBarButtonItem:

UIBarButtonItem *item = [[[UIBarButtonItem alloc] initWithCustomView:statusSegments_] autorelease]; 
+0

Cảm ơn. Điều đó có hiệu quả - nhưng có một thời gian khó khăn khi tìm thấy tài liệu đó? Bạn có một liên kết? –

+0

Chỉ là nó thuộc về, tài liệu 'UIToolbar': http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIToolbar_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006927- CH3-SW8 – Joost

+0

Cảm ơn, liên kết dẫn đến những gì tôi đã thấy trước đó: "Lớp UIBarButtonItem đóng gói các thuộc tính và hành vi của các mục được thêm vào các đối tượng UIToolbar và UINavigationBar." http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIBarButtonItem_Class/Reference/Reference.html –

Các vấn đề liên quan