2012-05-30 36 views
12

Tôi đang sử dụng bảng phân cảnh và tôi đã xem chế độ chia tách nơi chủ là UITableViewController. Giống như ứng dụng iPad Mail, tôi muốn hiển thị thanh công cụ UIToolbar.UIToolbar không hiển thị UIBarButtonItem

Tôi không thể thêm thanh công cụ qua bảng phân cảnh nhưng tôi đã quản lý thêm thanh công cụ theo chương trình. Tôi cũng có thể thêm một UILabel vào thanh công cụ, nhưng tôi không thể tìm thấy một cách để thêm một nút làm mới hoặc bất kỳ loại UIBarButtonItem.

Bất kỳ ý tưởng nào?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self.navigationController setToolbarHidden:NO]; 

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50.0f, 0.0f, 80.0f, 40.0f)]; 
    label.text = @"last updated..."; 
    label.textAlignment = UITextAlignmentCenter; 
    label.font = [UIFont systemFontOfSize:13.0]; 
    [self.navigationController.toolbar addSubview:label]; 

    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"Item" style:UIBarButtonItemStylePlain target:self action:@selector(action:)]; 
    UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithTitle:@"Item1" style:UIBarButtonItemStyleBordered target:self action:@selector(action:)]; 

    NSArray *buttons = @[item1, item2, nil]; 
    [self.navigationController.toolbar setItems:buttons animated:NO]; 

Trả lời

39

Tìm câu trả lời cảm ơn Diễn đàn Apple iOS!

Khi bạn sử dụng thanh công cụ của bộ điều khiển điều hướng, bạn phải đặt các nút trên thanh công cụ của trình điều khiển chế độ xem thuộc tính toolbarItems, chứ không phải trên thanh công cụ thực tế.

ví dụ:

[self setToolbarItems:buttons animated:NO]; 
+0

U lưu ngày của tôi !! .... Thanksss – sheetal

+0

Chết tiệt, thanks !! Điều này đã tiết kiệm thời gian! Cảm ơn! – yohannes

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