別のビュー内にビューが埋め込まれています。子ビューコントローラーで親ビューコントローラーの現在のインスタンスを取得するにはどうすればよいですか。現在のインスタンスで親のメソッドを呼び出す必要があります。
これは、現在親でメソッドを呼び出す方法です。これにより、新しいインスタンスが割り当てられます。
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
...
}