1

我可以正确调用“toggleMasterVisible”方法作为按钮操作,但我想像这样扩展该方法。

(In Button action. It works)
.h 
@interface DetailViewController : UIViewController <UISplitViewControllerDelegate>
@end

.m
UIBarButtonItem *listBarButtonItem = [[UIBarButtonItem alloc] 
initWithImage:[UIImage imageNamed:@"list.png"] 
style:UIBarButtonItemStyleBordered 
target:self.splitViewController 
action:@selector(toggleMasterVisible:)];


(I want to expand the method)
.m
UIBarButtonItem *listBarButtonItem = [[UIBarButtonItem alloc] 
initWithImage:[UIImage imageNamed:@"list.png"] 
style:UIBarButtonItemStyleBordered 
target:self 
action:@selector(toggleMasterVisibleIfCondtionIsOK:)];

-(void)toggleMasterVisibleIfCondtionIsOK
{
     if(isConditionOK){
          [self.splitViewController toggleMasterVisible];
     }
}

但是,我收到一个错误,即“没有可见的 @interface for 'UISplitViewController' 声明”。方法在哪里定义?我在参考上找不到方法(http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html),我该如何调用该方法?任何帮助将不胜感激。

4

2 回答 2

7

我得到了它的工作:

[self.splitViewController performSelector:@selector(toggleMasterVisible:)];
于 2013-04-04T16:49:18.153 回答
0

只需将其定义为匿名类别,如下所示:

@interface UISplitViewController()
- (void)toggleMasterVisible:(id)sender;
@end
于 2019-12-14T21:40:13.440 回答