我正在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
在视图控制器 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。但出现了很多警告。为什么会发生这种情况以及如何解决这个问题?谢谢