这是一个简单的问题,但我是新的xcode dev。我在网上按照指南在导航栏上有多个按钮。 navgivation栏上的编辑按钮有一个名为“editButton”的IBAction
方法。其中有一个(id)sender
作为参数。如何获取发件人并将编辑中的文本更改为完成,然后进行编辑?uitoolbar在导航栏中。
"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"];
}
}
那么我如何在editButton方法中获得双对象? – kraitz
就像你现在做的那样 - 通过从发件人转换它:UIBarButtonitem * bbi =(UIBarButonItem *)sender; –