我有一个嵌入视图,在另一个视图中,我将如何在 Childs viewController 中获取父 viewController 的当前实例,需要它在当前实例上调用父级上的方法。
这就是我当前在父级上调用该方法的方式,这会分配一个新实例。
CalendarMonthViewParent *controller = [[CalendarMonthViewParent alloc] init];
[controller callChildChange];
我得到“没有可见的界面声明”callChildChange”,如果我这样称呼它:
[self.parentViewController callChildChange];
编辑1:
CalendarMonthViewParent.h
#import <UIKit/UIKit.h>
@interface CalendarMonthViewParent : UIViewController
-(void) callChildChange;
@property (strong, nonatomic) IBOutlet UINavigationItem *skemaNavigationItem;
@end
CalendarMonthViewParent.m
- (void)callChildChange { // this is called from the child
UINavigationItem *navBar = [self skemaNavigationItem];
NSLog(@"logging navItem: %@", navBar); // this logs null when called from the child, since its called on a new instance and not the old one, if i call this from the parent directly, it is not null
}
CalendarMonthViewChild.m
- (void) calendarMonthView:(TKCalendarMonthView*)monthView didSelectDate:(NSDate*)date{
NSLog(@"Date Selected: %@",date);
...
CalendarMonthViewParent *controller = [[CalendarMonthViewParent alloc] init];
[controller callChildChange]; // this calls it on a new instance, i need it to call it on the existing instance
...
}