在视图与其子视图之间传递 int
我有一个名为 PatternsViewController 的视图和一个名为 SolutionsViewController 的子视图。我想在将 PatternsViewController 中名为迭代的变量传递给我的 SolutionsViewController 之前,先将其呈现
solutions = [[SolutionsViewController alloc] init];
solutions.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:solutions animated:YES];
I have a view called PatternsViewController and a subview named SolutionsViewController. I want to pass a variable in PatternsViewController named iteration to my SolutionsViewController, right before I present it with
solutions = [[SolutionsViewController alloc] init];
solutions.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:solutions animated:YES];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我通过稍微修改 Squeegy 的代码来解决这个问题。
在 PatternsViewController.m
和 SolutionsViewController.m 中
I figured it out by slightly modifying Squeegy's code.
In PatternsViewController.m
and in SolutionsViewController.m
我会使用 Singleton 类。
我的 Objective-C 单例应该是什么样子?
然后你可以这样做:
并通过以下方式访问它:
I would use a Singleton class.
What should my Objective-C singleton look like?
Then you can do like:
And access it with:
为什么不简单地用一个额外的参数来覆盖 init 并接受你想要设置的 int 呢?这允许干净的实例化,而无需添加设置调用。
Why not simply over-ride the init with an additional argument that take the int you want to set? This allows a clean instantiation without an added set call.
所选答案对我有用,但它给了我一个语义警告。即使代码有效,我对警告还是有点记忆犹新,所以我想知道是否有一种方法可以让它在没有警告的情况下工作。
警告是:
找不到实例方法“-SetPrompt:”(返回类型默认为“id”)
这是我在遵循此问题的答案时所做的操作。
在调用 .m 文件中
在接收 .m 文件中
The selected answer works for me but it is giving me a semantic warning. I'm a little annal retentive about warnings even if the code works so I am wondering if there is a way to make it work without the warning.
The warning is:
Instance method '-SetPrompt:' not found (return type defaults to 'id')
Here is what I did while following along to the answer in this question.
In the calling .m file
In the receiving .m file
在
SolutionsViewController
中And in
SolutionsViewController