我正在为iOS开发基于SplitView的应用程序
我在主视图控制器上添加了一个用于隐藏此视图的按钮,我这样做了
MasterViewController.m
- (IBAction)hideMasterViewController:(id)sender {
if (!app) { app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; }
if (!currentSplitViewController) {
currentSplitViewController = (UISplitViewController *) app.window.rootViewController;
}
navController = [currentSplitViewController.viewControllers lastObject];
UIBarButtonItem *button = [[[[navController childViewControllers] objectAtIndex:0] navigationItem ] leftBarButtonItem];
[button.target performSelector:button.action];
}
你可以看到我在我自己的按钮上添加了Detail View Controller的leftBarButtonItem的功能,然后我命令在这里执行它自己的选择器
[button.target performSelector:button.action];
但现在我收到了这个警告:
PerformSelector可能会因为其选择器未知而导致泄漏
我这样做,因为细节控制器已预先构建它,我不知道它的选择器的名称,如何知道???
编辑:这些是我的两个屏幕:
DetailViewController (原始预建按钮)
MasterViewController (我在详细视图中从预建按钮开发了我的按钮克隆)
编辑:感谢耶稣回答:
- (IBAction)hideMasterViewController:(id)sender {
if (!app) { app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; }
if (!currentSplitViewController) {
currentSplitViewController = (UISplitViewController *) app.window.rootViewController;
}
navController = [currentSplitViewController.viewControllers lastObject];
UIBarButtonItem *button = [[[[navController childViewControllers] objectAtIndex:0] navigationItem ] leftBarButtonItem];
[button.target performSelector:@selector(toggleMasterVisible:)];
}
-(IBAction)toggleMasterVisible:(id)sender{
}
NSStringFromSelector(button.action)
答案 0 :(得分:1)
使用此:
NSStringFromSelector(button.action)