【发布时间】:2011-11-29 02:13:34
【问题描述】:
这是一个简单的问题,但我是 xcode 开发的新手。我按照在线指南在导航栏上有多个按钮。导航栏上的编辑按钮有一个名为“editButton”的IBAction 方法。其中有一个(id)sender 作为参数。我是否得到发件人并将文本从编辑更改为完成,完成编辑?
"UIBarButtonitem *bbi = (UIBarButonItem *) sender;" 似乎不起作用。如何在导航栏的工具栏中获取按钮?
谢谢。
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3];
// create a standard "add" button
UIBarButtonItem* bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:NULL];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// create a spacer
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[buttons addObject:bi];
[bi release];
// create a standard "EDIT" button
bi = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editButton:)];
bi.style = UIBarButtonItemStyleBordered;
[buttons addObject:bi];
[bi release];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
[buttons release];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
[tools release];
-(IBAction)editButton:(id) sender{
UIBarButtonitem *bbi = (UIBarButonItem *) sender;
if (bbi title isequalsString:@"Done){
[bbi setTitle:@"Edit"];
}
}else{
[bbi setTitle:@"Done"];
}
}
【问题讨论】: