我尝试在navigationcontrollers顶视图中设置工具栏项。似乎在子视图中工作......但为什么不在顶视图中...任何想法?我收到了添加按钮...但不是我的自定义按钮。
- (void)configureToolbarItems {
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self action:@selector(addNewTaskButtonPressed)];
//Green button
greenButton=[app makeGreenButton:self];
UIBarButtonItem *greenBarButton = [[UIBarButtonItem alloc] initWithCustomView:greenButton];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
// Set our toolbar items
[self setToolbarItems:[NSArray arrayWithObjects:
addButtonItem,flexibleSpace, greenBarButton, nil] animated:YES]; }
这是makeButton程序......在其他视图中工作正常:
-(UIButton*)makeGreenButton:(UIViewController*)caller {
UIButton *greenButton;
//load the image for yellow button
UIImage *greenButtonImage = [UIImage imageNamed:@"greenButton.png"];
//create the button and assign the image
greenButton = [UIButton buttonWithType:UIButtonTypeCustom];
[greenButton setImage:greenButtonImage forState:UIControlStateNormal];
greenButton.showsTouchWhenHighlighted=TRUE;
//set the frame of the button to the size of the image (see note below)
greenButton.frame = CGRectMake(0, 0, greenButtonImage.size.width*2, greenButtonImage.size.height*2);
//Add target
[greenButton addTarget:caller action:@selector(greenButtonReleased:) forControlEvents:UIControlEventTouchUpInside];
return greenButton; }