@interface GuidePager : UIViewController <UIPageViewControllerDataSource, UIPageViewControllerDelegate>
@property (strong, nonatomic) UIPageViewController *pageController;
@property NSArray *viewControllers;
- (void)flipToPage:(NSString *)index;
@end
和
@interface GuidePagerChild : UIViewController <UIWebViewDelegate>
@end
我需要从GuidePagerChild调用GuidePager的flipToPage,其中GuidePagerChild。
请帮忙。
答案 0 :(得分:3)
为孩子添加委托协议:
@protocol GuidePagerChildDelegate;
@interface GuidePagerChild : UIViewController <UIWebViewDelegate>
@property (nonatomic, weak) id<GuidePagerChildDelegate> delegate;
@end
@protocol GuidePagerChildDelegate <NSObject>
@required
- (void)guidePagerChild:(GuidePagerChild *)child flipToPage:(NSString *)index
@end
然后:
@interface GuidePager : UIViewController <
GuidePagerChildDelegate, // Add the new protocol to the list.
UIPageViewControllerDataSource,
UIPageViewControllerDelegate
>
@property (strong, nonatomic) UIPageViewController *pageController;
@property NSArray *viewControllers;
- (void)flipToPage:(NSString *)index;
@end
然后当你创建孩子时:
GuidePagerChildDelegate *child = [[GuidePagerChild alloc] init]; // Or however you create it.
child.delegate = self; // Assuming you create it from within GuidePager. If not, get a pointer to GuidePager and set it as the delegate.
然后:
@implementation GuidePager
...
- (void)guidePagerChild:(GuidePagerChild *)child flipToPage:(NSString *)index
{
[self flipToPage:index];
}
...
@end