我做了一个自定义委托:
示例.h:
@protocol DismissExamplePopoverDelegate
- (void) dismissExamplePopover;
- (int) getUserID;
@end
@interface Example : UIViewController{
id<DismissExamplePopoverDelegate> delegate;
}
@property (nonatomic, assign) id<DismissExamplePopoverDelegate> delegate;
它在 Example.m 中被调用,如下所示:
[[self delegate] getUserID];
在我的 maincontroller.h 中:
#import "Example.h"
@interface MainScreen : UIViewController<DismissExamplePopoverDelegate>
主控制器.m:
-(int) getUserID
{
return 100;
}
视图示例通过以下方法调用:
ExampleController = [[Example alloc] initWithNibName:@"Example" bundle:nil];
ExamplePopoverController = [[UIPopoverController alloc] initWithContentViewController:ExampleController];
[ExampleController setDelegate:self];
ExamplePopoverController.popoverContentSize = CGSizeMake(600, 480);
if ([ExamplePopoverController isPopoverVisible]) {
[ExamplePopoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake((self.EditExampleSelectAddButtonProperty.frame.origin.x),
(self.EditExampleSelectAddButtonProperty.frame.origin.y),
(self.ExampleSelectAddButtonProperty.frame.size.width),
(self.ExampleSelectAddButtonProperty.frame.size.height));
[ExamplePopoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
如果我放置[[self delegate] getUserID]
在任何其他函数中,viewdidload
它都可以正常工作:返回 100;其中viewdidload
返回 0。
我想要实现的是在弹出框加载时自动调用的委托。viewdidload 是最适合它的地方,还是在其他地方