将变量传递给另一个视图
我正在尝试在另一个视图中设置变量。
我位于一个名为 ProgramViewController 的视图中,我想在 MyViewController 中设置一个名为 bands
的变量。
我认为它会像
MyViewController *myViewController = [[MyViewController alloc] init];
myViewController.bands = @"hello world";
[myViewController release];
MyViewController 的标题中的 And 一样简单:
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
NSString *bands;
}
@property (nonatomic, retain) NSString *bands;
但这不起作用。
谁能告诉我我做错了什么吗?
编辑: 我在 MyViewController 中合成 bands
:
@synthesize pageNumberLabel, tableProgram, bands;
但是当尝试在 MyViewController 的 viewDidLoad 中使用 NSLog
打印它时,我得到 (null)
NSLog( @“%@”,带);
I'm trying to set a variable in another view.
I'm in a view which I have named ProgramViewController and from here I would like to set a variable named bands
in MyViewController.
I thought it would be as simple as
MyViewController *myViewController = [[MyViewController alloc] init];
myViewController.bands = @"hello world";
[myViewController release];
And in the header of MyViewController:
@interface MyViewController : UIViewController <UITableViewDataSource, UITableViewDelegate> {
NSString *bands;
}
@property (nonatomic, retain) NSString *bands;
That does not work, though.
Can anyone please tell me what I am doing wrong?
EDIT:
I synthesize bands
in MyViewController:
@synthesize pageNumberLabel, tableProgram, bands;
But when trying to print it with NSLog
in the viewDidLoad of MyViewController I get (null)
NSLog(@"%@", bands);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在 MyViewController.m 中合成 band 变量
需要合成变量才能将其用作 Objective-C 中类的公共属性
You need to synthesize the bands variable in MyViewController.m
A variable needs to be synthesize in order to use it as a public property outsize of a class in Objective-C
我用另一种方式解决了这个问题。我设法在 MyViewController 中加载数据。我正在处理页面控制器,必须填充 UITableView,但在加载数据时遇到问题。
现在这个问题已经通过完全不同的方式解决了。
I solved this in another way. I managed to load the data in MyViewController instead. I was dealing with a page controller and had to populate a UITableView but had troubles loading the data.
This is solved in a completely other way now.