&tag(Objective-C, UIKit);
- (void)viewDidLoad {
[super viewDidLoad];
//"+"ボタンを生成
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(newPushed)];
//右側のボタンにセット
self.navigationItem.rightBarButtonItem = newButton;
// わすれずrelease。最初にautoreleaseしておくのでも良い。
[newButton release];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
UIBarButtonItem *actionButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:self
action:@selector(actionPushed)] autorelease];
self.navigationItem.rightBarButtonItem = actionButton;
}
- (void)actionPushed {
UIActionSheet *sheet = [[[UIActionSheet alloc] init] autorelease];
sheet.delegate = self;
[sheet addButtonWithTitle:@"テスト1"];
[sheet addButtonWithTitle:@"テスト2"];
[sheet addButtonWithTitle:@"Cancel"];
sheet.cancelButtonIndex = 2;
[sheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
NSLog(@"テスト1が押されました");
} else if (buttonIndex == 1) {
NSLog(@"テスト2が押されました");
}
}