hii every one
i am creating a navigation based application &a开发者_高级运维mp; i am designing screens programatically , i need to have 2 bar buttons ie left barbutton item & right bar button item so i have used following code in - (void)loadView method but its crashing when controller enters loadview method,,can any one tell me whats wrong in this code, thanx in advance
self.title = @"Add Item";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancel_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:@selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
Try this code
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:@"Flip"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(flipView)];
self.navigationItem.rightBarButtonItem = flipButton;
[flipButton release];
Try following code,
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn addTarget:self action:@selector(yourfunctionToCall:) forControlEvents:UIControlEventTouchUpInside];
btn.frame=CGRectMake(3, 2, 53, 30);
UIBarButtonItem *btnBack=[[UIBarButtonItem alloc] initWithCustomView:btn];
self.navigationItem.leftBarButtonItem=btnBack;
[btnBack release];
[btn release];
same way create for rightBarButtonItem
self.title = @"Add Item";
UIBarButtonItem *cancelbutton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancel_Clicked:)] autorelease];
self.navigationItem.leftBarButtonItem=cancelbutton;
[cancelbutton release];
UIBarButtonItem *savebutton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:@selector(save_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem=savebutton;
[savebutton release];
精彩评论