我在 OneViewController.h 中声明了一个方法“someMethod”
@interface OneViewController
{
UIView *tempView;
..
}
-(void) someMethod ;
@end
并在 OneViewController.m 文件中实现
@implementation OneViewController
-(void) someMethod
{
tempView = [[UIView alloc]initWithFrame:CGRectMake(100, 50, 200, 250)];
tempView.backgroundColor = [UIColor yellowColor];
if([[self.view subviews] containsObject:tempView])
[tempView removeFromSuperView];
else
[self.view addsubview:tempView];
}
我想打电话一些方法当出现在不同的 viewController 中时 - secondaryViewController
(就像是[OneViewController someMethod]
),这样当我回到 One ViewController 时,我可以看到所做的更改一些方法.
我需要使用 appDelegate 方法吗?
我已经尝试遵循但它不起作用。
neViewController *newViewController = [[OneViewController alloc] init];
[newViewController someMethod];
感谢您提前提供任何帮助..
在 SecondViewController 中,声明 OneViewController 类的引用。您可以分配财产。在移动到 SecondViewController 之前设置引用。现在有了引用,就可以调用实例方法了[_oneView someMethod]
.
Edit:
Declare
OneViewController *_oneView;
还添加分配属性,
@property(nonatomic,assign) OneViewController *_oneView;
综合 .m 文件中的变量。
从 OneViewController 显示 SecondViewController 时,只需添加以下行。
secondView._oneView = self;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)