0
我有一個在界面生成器中創建的UIPickerview。通過代碼,我將工具欄作爲其子視圖,並將完成按鈕作爲工具欄欄按鈕項。我想在完成按鈕被點擊時執行一個動作(隱藏pickerview和一些額外的東西)。但由於某種原因,完成按鈕的操作不起作用。這裏是在viewDidLoad中創建工具欄和欄按鈕項目的代碼。UIBarButtonItem對放置在pickerview中的工具欄不起作用
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
toolBar.barTintColor = [UIColor colorWithRed:70/250.0f green:70/250.0f blue:70/250.0f alpha:1.0];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleDone target:self action:@selector(doneButtonTapped:)];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
toolBar.items = @[flexible, barButtonDone, flexible];
barButtonDone.tintColor=[UIColor colorWithRed:227/255.0f green:178/255.0f blue:49/255.0f alpha:1.0];
[picker addSubview:toolBar];
[picker bringSubviewToFront:toolBar];
這裏是方法doneButtonTapped:
-(void)doneButtonTapped:(UIBarButtonItem *)sender{
NSLog(@"Done button tapped");
picker.hidden = true;
[self.view bringSubviewToFront:txtCity];
[self.view bringSubviewToFront:advancedSearchLine];
[self.view bringSubviewToFront:txtCityLine];
}
我在佈局調試檢查,同時運行的應用程序,並確實完成按鈕在視圖中的前面,所以沒有在它的前面阻止它工作。我究竟做錯了什麼?
你加入爲pickerview子視圖不這樣做,拿來看,頂部添加工具欄上添加你的pickerview後續工具欄 –
。謝謝 –
的意思沒關係了它選取器工具欄後續 –