trong ứng dụng của tôi Tôi có một thanh công cụ và tại một thời điểm nhất định mà tôi muốn tắt hoặc bật một số nút. Cách dễ nhất để làm như vậy là gì? Làm thế nào tôi có thể truy cập các thuộc tính của UIToolbar?UIToolBar - tắt các nút
Đây là mã của tôi:
-(void)addToolbar {
NSMutableArray *buttons = [[NSMutableArray alloc] init];
//Define space
UIBarButtonItem *flexibleSpaceItem;
flexibleSpaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
//Add "new" button
UIBarButtonItem *newButton = [[UIBarButtonItem alloc]
initWithTitle:@"New" style:UIBarButtonItemStyleBordered target:self action:@selector(new_clicked)];
[buttons addObject:newButton];
[newButton release];
//Add space
[buttons addObject:flexibleSpaceItem];
//Add "make active" button
UIBarButtonItem *activeButton = [[UIBarButtonItem alloc]
initWithTitle:@"Make Active" style:UIBarButtonItemStyleBordered target:self action:@selector(make_active_clicked)];
[buttons addObject:activeButton];
[activeButton release];
[buttons addObject:flexibleSpaceItem];
//Add "edit" button
UIBarButtonItem *editButton = [[UIBarButtonItem alloc]
initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(edit_clicked)];
[buttons addObject:editButton];
[editButton release];
[flexibleSpaceItem release];
[toolBar setItems:buttons];
[buttons release];
}
Cảm ơn bạn trước.
Bạn cũng có thể tắt tương tác người dùng trên thanh công cụ (userInteractionEnbaled = NO) – jjxtra