我已经制作了一个标准的主从应用程序(使用 Xcode 模板)。我修改了它,现在当我单击第一个表格 View 的一个单元格时,应用程序会显示另一个表格 View (这是详细信息,因为它是由单击的单元格值过滤的)。 在标准表格 View 中,我会在 UINavigationBar 上遇到这种情况:
Edit Table title + (for adding new items)
我也需要 UINavigationBar 的默认后退按钮。是否有可能并允许这样做?从图形上看应该是这样的:
< Back Table title Edit +
您知道在顶部栏中显示 3 个按钮(返回 - 编辑 - 添加)和标题的任何其他布局吗?
抱歉没有发布图片,在此先感谢。
附言我想知道是否可以使用内置的后退按钮和编辑按钮(我的意思是系统自动放入导航栏的按钮)来完成我要求的事情。
最佳答案
您需要设置右侧栏项目数组以设置右侧的栏按钮...
这里是 2 个自定义按钮的代码,用于设置右侧的栏按钮项目......你可以使用默认按钮而不是这个
UIButton *btnabout = [UIButton buttonWithType:UIButtonTypeCustom];
btnabout.frame = CGRectMake(0,8,30,30);
[btnabout setBackgroundImage:[UIImage imageNamed:@"about.png"] forState:UIControlStateNormal];
[btnabout addTarget:self action:@selector(callselector) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithCustomView:btnabout];
about.tintColor = [UIColor whiteColor];
UIButton *btnsetting = [UIButton buttonWithType:UIButtonTypeCustom];
btnsetting.frame = CGRectMake(0,8,30,30);
[btnsetting setBackgroundImage:[UIImage imageNamed:@"setting"] forState:UIControlStateNormal];
[btnsetting addTarget:self action:@selector(SettingData) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *setting = [[UIBarButtonItem alloc] initWithCustomView:btnsetting];
setting.tintColor = [UIColor whiteColor];
self.navigationItem.rightBarButtonItems =[NSArray arrayWithObjects:setting, about, nil];
// --- or if you want left side ----
// self.navigationItem.leftBarButtonItems =[NSArray arrayWithObjects:setting, about, nil];
关于ios - 如何在 UINavigationBar 的右侧设置两个按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31612471/