有两个屏幕,要实现点击第一个屏幕导航栏的按钮,在第二个屏幕中改变。我用了storyboard。
第一个屏幕的代码:
-(IBAction) ChangeSecondPageTitle: (id) sender {
SecondViewController *second=[[self storyboard] instantiateViewControllerWithIdentifier:@"second"];
second.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
second.detailTitle.topItem.title=@"example";
[self presentModalViewController:second animated:YES];
}
第二个屏幕的.h文件:
@property (weak, nonatomic) IBOutlet UINavigationBar *detailTitle;
我猜想你是要设置第二屏幕导航条的标题
使用导航控制器显示第二个屏幕。
在SecondDetailViewController 市里中,保持NSString属性:
@property (strong, nonatomic) NSString *navBarTitle;
在viewDidLoad,设置标题:
[self setTitle:navBarTitle];
不需要设置navigationbar 为IBOutlet
设置title需要在SecondViewController内部来设置,你可以添加一个属性来给title赋值
@interface SecondViewController : UIViewController
@property (nonatomic,retain) NSString *title;
@end
在.m文件中
@implementation SecondViewController
-(void)viewDidLoad {
self.navigationItem.title=self.title;
}
@end
修改ChangeSecondPageTitle 方法
second.title=@"example";
[self presentModalViewController:second animated:YES];