我似乎无法在工具栏中的 iPad 右上角放置一个简单的按钮。我在 viewDidLoad 方法中有代码。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
/*
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
self.navigationItem.rightBarButtonItem = addButton;
*/
UIImage *image = [UIImage imageNamed:@"camera_30_30.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:image forState:UIControlStateNormal];
button.frame = CGRectMake( 0, 0, image.size.width, image.size.height);
button.showsTouchWhenHighlighted = YES;
[button addTarget:self action:@selector(myAction) forControlEvents:UIControlEventTouchUpInside];
//UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleBordered target:self action:@selector(insertNewObject:)];
NSMutableArray *items = [[NSMutableArray alloc] init];
[items addObject:barButtonItem];
//self.toolbarItems = items;
self.navigationItem.rightBarButtonItem = barButtonItem;
}