sha*_*ikh 12 iphone xcode uinavigationcontroller uibarbuttonitem ios
这是我的代码.我想在开放的rootviewController上放一个后退按钮.
- (void)selectSurah:(id)sender {
SurahTableViewController * surahTableViewController = [[SurahTableViewController alloc] initWithNibName:@"SurahTableViewController" bundle:nil];
surahTableViewController.navigationItem.title=@"Surah";
surahTableViewController.navigationItem.backBarButtonItem.title=@"Back";
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:surahTableViewController];
[self presentModalViewController:aNavigationController animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我不相信可以将根视图控制器从导航堆栈中弹出,但您可以将其UIButton添加为自定义视图UIBarButtonItem:
UIButton *b = [[UIButton alloc]initWithButtonType:UIButtonTypeCustom];
[b setImage:[UIImage imageNamed:@"BackImage.png"] forState:UIControlStateNormal];
[b addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];
self.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:b];
Run Code Online (Sandbox Code Playgroud)
可以在此处找到适合的iOS UI元素的PSD .
Faizan,
Helium3评论很有意义.
我想你的按钮需要以模态方式解除控制器,这是真的吗?如果我错了,请纠正.
如果是这样,你可以创建一个新的,UIBarButtonItem并设置为左(或右)按钮UINavigationController navigationItem.要不破坏封装,请在控制器的viewDidLoad方法中创建它SurahTableViewController.
- (void)viewDidLoad
{
[super viewDidLoad];
// make attention to memory leak if you don't use ARC!!!
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(close:)];
}
-(void)close:(id)sender
{
// to dismiss use dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion
// dismissModalViewControllerAnimated: is deprecated
[self dismissViewControllerAnimated:YES completion:^{ NSLog(@"controller dismissed"); }];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11288 次 |
| 最近记录: |