0
我有一個自定義視圖,它有一個UIButton。我將這個視圖添加到我的navigationItem的rightbarButtonItem,沒關係,但我必須添加一個動作到這個按鈕。添加動作到自定義視圖中的UIButton
這是我的代碼;
-(void)showMessage:(id)sender
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"next" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
}
- (void)viewDidLoad {
UpDownButtonView *buttonView = [[UpDownButtonView alloc] initWithNibName:@"UpDownButtonView" bundle:nil];
[buttonView.upButton addTarget:self action:@selector(next:) forControlEvents:UIControlEventTouchUpInside];
[buttonView.downButton addTarget:self action:@selector(prev:) forControlEvents:UIControlEventTouchUpInside];
buttonView.view.frame = CGRectMake(0,0,95,34);
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWithCustomView:buttonView.view];
self.navigationItem.rightBarButtonItem = item;
[self setTitle:@"Details"];
[super viewDidLoad];
}
謝謝。
是的,但我可能會添加更多的按鈕或其他東西,所以我需要在自定義視圖中進行操作。有什麼想法嗎? – Can 2010-12-17 10:15:41