我在MainViewController中有一个UIButton。
MainViewController有一个childViewContoller。iOS访问parentViewController来更改UIButton的状态setSelected:是
我需要从MainViewController中访问childViewController中的UIButton(tcButton)属性,并将它设置为setSelected:YES在viewDidLoad中。我在我的ChildViewController.m文件中有以下代码,它不起作用。
#import "ChildViewController.h"
#import "MainViewController.h"
#import "CoreData.h"
@interface ChildViewContoller()
@property (nonatomic, strong) CoreData *coreData;
@property (nonatomic, strong) MainViewController *mainViewController;
@end
@implementation ChildViewController
@synthesize coreData, mainViewController;
-(void)viewDidLoad
{
[super viewDidLoad];
self.managedObjectContext = [(STAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
[[(mainViewController *)self.parentViewController tcButton] setSelected:YES];
}
rdelmar:我以为同样的事情,第一次尝试: [self.parentViewController tcButton] setSelected = YES]; ,并给了我错误:无可见@interface'UIViewController'声明选择器'tcButton' 然后我开始使用Google,看到上面的代码。 但是,现在我正在尝试您的代码,并且出现以下错误: 解析问题预期的表达式。 (MainViewController *)的右括号处指向光标箭头。是的,我在最后有一个分号,我复制并粘贴了您的代码。谢谢。 – user1107173 2013-02-10 22:33:55
@ user1107173,哦,对不起,我输入了错误,应该在末尾设置选择:YES(not =)。 – rdelmar 2013-02-10 22:42:19
感谢您的快速回复。我将其更改为setSelected:YES];而且我仍然得到相同的Parse Issue Expected表达式。光标箭头指向(MainViewController *)的右括号。 – user1107173 2013-02-10 22:58:01