在 iOS 7 中,UIBarButtonItem 不会显示在我的 UIToolbar 上,它会在表格视图的底部弹出。
UIToolbar *actionToolbar;
UIBarButtonItem *actionButton;
我像这样添加它:
actionToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 524, 320, 44)];
actionButton =
[[[UIBarButtonItem alloc]
initWithTitle:@"Delete"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(noAction:)]
autorelease];
[actionToolbar setItems:[NSArray arrayWithObject:actionButton]];
这是显示 UIToolbar 的代码:
- (void)showActionToolbar:(BOOL)show
{
CGRect toolbarFrame = actionToolbar.frame;
CGRect tableViewFrame = self.tableView.frame;
if (show)
{
TOOLBAR_DISPLAYED = TRUE;
toolbarFrame.origin.y = actionToolbar.superview.frame.size.height - toolbarFrame.size.height;
tableViewFrame.size.height -= toolbarFrame.size.height;
}
else
{
TOOLBAR_DISPLAYED = FALSE;
toolbarFrame.origin.y = actionToolbar.superview.frame.size.height;
tableViewFrame.size.height += toolbarFrame.size.height;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
actionToolbar.frame = toolbarFrame;
self.tableView.frame = tableViewFrame;
//I use this now in iOS7 to show the toolbar as purple otherwise it shows white
actionToolbar.superview.backgroundColor = [UIColor colorWithRed:0.10 green:0.10 blue:0.43 alpha:0.5];
[UIView commitAnimations];
}
这在以前的版本上运行良好,我不知道现在可能是什么问题。