내비게이션 컨트롤러 안에있는 TableViewController의 아래쪽에 툴바 항목을 표시하려고합니다. 나는 Swift에서이 코드를 작성했다.Swift를 사용하여 NavigationController에 툴바 항목을 표시 할 수 없습니다.
저는 Xcode 기본 마스터 - 세부 템플릿을 사용하여 프로젝트를 만들고 MasterTableViewController의 ViewDidLoad 메서드에 아래 코드를 작성했습니다.
문제를 해결하는 데 도움을주십시오.
다음 코드 스 니펫을 찾으십시오.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.addToolBar();
}
func addToolBar()->Void {
self.hidesBottomBarWhenPushed = false
var toolBarItems = NSMutableArray()
var systemButton1 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Play, target: nil, action: nil)
toolBarItems.addObject(systemButton1)
var systemButton2 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
toolBarItems.addObject(systemButton2)
var systemButton3 = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Trash, target: nil, action: nil)
toolBarItems.addObject(systemButton3)
self.navigationController?.toolbarHidden = false
self.setToolbarItems(toolbarItems, animated: true)
//self.navigationController?.toolbarItems = toolbarItems;
}
은 그러나 흥미롭게도, 오브젝티브 C로 작성된 동일한 코드가 작동하고 두 항목
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
[self addToolbar];
}
-(void) addToolbar
{
self.hidesBottomBarWhenPushed = NO;
NSMutableArray *items = [[NSMutableArray alloc] init];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:nil action:nil];
[items addObject:item1];
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:item2];
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil];
[items addObject:item3];
self.navigationController.toolbarHidden = NO;
// self.navigationController.toolbarItems = items;
//
[self setToolbarItems:items animated:YES];
}
뷰 컨트롤러의 기본 속성으로 (대소 문자 제외) 동일하지의 이름을 사용하는 것이 좋을 것이다 일했다. 당신의 오타 (Matthias의 답변에서 지적한)는 이것 때문에 컴파일러에 잡히지 않았습니다. – rdelmar