我想在我的UIToolBar上單擊完成按鈕時調出「TableViewController」的.nib。但下面的內容不允許點擊來創建新視圖。我該如何糾正這一點?請告訴我我錯在哪裏,應該替換什麼以及爲什麼。如何給barbuttonitem行動?
//Here's the selector in my overlay.
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed)];
//Here's how I made my action. Btw, the uitoolbar has no nib, it's an overlay on the
//(camera mode).
-(void)doneButtonPressed {
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:@"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
}
//Yet nothing happens when I click on my done button on my overlay. And I've made sure
// i've imported .h frameworks correctly too.
假設你是從barbuttonitem這是一個UItoolbar覆蓋帶來了一個筆尖。你會怎麼做?
我被告知,爲了使它正常工作,我必須添加[barButtonItem addTarget:self action:@selector(doneButtonPressed)forControlEvents:UIControlEventTouchUpInside]; 。
但是,如果我添加它,我得到這個:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone addTarget:self action:@selector(doneButtonPressed)
forControlEvents:UIControlEventTouchUpInside];
導致我得到一個錯誤閱讀「實例方法‘ - initWithBarButtonSystemItem:目標:動作:forControlEvents:’未找到(返回類型默認爲' id')「
除了向我展示正確的添加劑之外,請向我展示除我在此處編寫的代碼之外的解決方案。
我以編程方式製作barbuttonitem,因爲它所在的工具欄是以編程方式製作的,所以使用IB並不可行。 – Capricorn 2012-08-01 19:06:37