我正在iOS中尝试pushViewController,但是执行结果如下
当我按下按钮时,它将从视图A过渡到视图B。
这是我的视图A的代码
#import <UIKit/UIKit.h>
#import "ViewControllerB.h"
@interface ViewControllerA : UIViewController
-(IBAction)next:(id)sender;
@end
在.m文件中
#import "ViewControllerA.h"
@interface ViewControllerA ()
@end
@implementation ViewControllerA
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
-(IBAction)next:(id)sender
{
ViewControllerB *viewController=[[ViewControllerB alloc]init];
viewController.string=@"tunvir";
[self.navigationController pushViewController:viewController animated:YES];
}
@end
在viewController B中
@interface ViewControllerB : UIViewController
@property (nonatomic,strong)NSString *string;
@end
在.m文件中
#import "ViewControllerB.h"
@interface ViewControllerB ()
@end
@implementation ViewControllerB
@synthesize string=_string;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
@end
要在viewB中将字符串设置为“ tunvir”并将对象加载为viewB。但是会出现很多警告。为什么会发生这种情况以及如何解决?
最佳答案
如果您只需要为View Controller App>的导航栏设置标题
如果您使用Storyboard,请使用EDIT
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.navigationItem.title = @"Title for NavigationBar";
}
关于ios - viewController和pushViewcontroller无法正常工作?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16539766/