C.J*_*hns 19 iphone back-button uinavigationbar ios
我目前正在尝试更改加载了tablecell touch的子视图的后退按钮文本.然而,即使按照我尝试实现它的方式,它仍然在后退按钮中显示父母标题.
我试图在viewdidload方法中的后退按钮中加载一个新值,就像这样
UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init];
myBarButtonItem.title = @"Back";
self.navigationItem.backBarButtonItem = myBarButtonItem;
[myBarButtonItem release];
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
小智 30
你需要改变self.navigationItem.backBarButtonItem以前的观点,而不是当前的观点(我知道,这看起来有点不合逻辑).例如,在表视图中,您可以执行以下操作:
- (void)viewDidLoad
{
[super viewDidLoad];
[self setTitle:@"My title"];
UIBarButtonItem *boton = [[UIBarButtonItem alloc] initWithTitle:@"Custom back button text" style:UIBarButtonItemStyleBordered target:self action:@selector(mySelector:)];
self.navigationItem.backBarButtonItem = boton;
[boton release];
}
Run Code Online (Sandbox Code Playgroud)
小智 26
在您阅读并重新阅读并使用每个设置之前,这是文档不太清楚的地方.
要更改默认后退按钮的标题,请添加此行viewDidLoad()
self.navigationController.navigationBar.topItem.title = @"Your Label";
Run Code Online (Sandbox Code Playgroud)
如果希望按钮不可见 - 则将值设置为@""空字符串.
好吧想通了,我在父视图tableView:didSelectRowAtIndexPath:方法中发布了这段代码.这就是我的用户可以选择多个tablecells的方式.希望这可以帮助.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
if (indexPath.section == 0) { //--- picks (first) section
ChildViewController *childViewController = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:childViewController animated:YES];
//--- this sets the back button to "Back" every time you load the child view.
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
if(indexPath.row == 0) { //--- picks row
childViewController.title = @"Bike";
}
if(indexPath.row == 1) {
childViewController.title = @"Model";
}
[vehicleSearchResponseTableViewController release];
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,您的代码看起来不错。
这段代码是在之前执行的吗
[super viewDidLoad];
Run Code Online (Sandbox Code Playgroud)
声明(错误)还是声明之后(好)?
| 归档时间: |
|
| 查看次数: |
21488 次 |
| 最近记录: |