2012-04-09 75 views
1

我有一个UISplitViewConroller的通用应用程序。我正在使用故事板。委托没有在iOS5 StoryBoard中设置UISplitViewController

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) 
{ 
     UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController; 
     UINavigationController *masterNavigationController = [splitViewController.viewControllers objectAtIndex:0]; 
     LeftViewContrller *lcontroller = (LeftViewContrller *)masterNavigationController.topViewController; 
     id<SplitViewDelegate> rightController = (id<SplitViewDelegate>)[splitViewController.viewControllers objectAtIndex:1]; 
     lcontroller.delegate = rightController; 
} 

我有一个UISplitViewController应用程序的左和右控制器。

LeftViewController有一个自定义委托,它被设置为RightViewController。

//Custom delegate 

@protocol SplitViewDelegate <NSObject> 

- (void) matchSelectionChanged:(NSString *)curSelection; 

@end 

//LeftViewContoller 

@interface LeftViewContrller : UITableViewController { 
    id<SplitViewDelegate> _delegate; 
    NSMutableArray *_matches; 
} 
@property (strong) id<SplitViewDelegate> delegate; 
@property (strong) NSMutableArray *matches; 

@end 

RightViewController实现此委托协议。但是,当在LeftViewController中单击行内的单元格时,代表失败。

//RightViewController 
@interface RightViewController : UIViewController <SplitViewDelegate> 

@property (weak,nonatomic) IBOutlet UILabel *matchLabel; 

@end 

//Implementation of RightViewController 
- (void) matchSelectionChanged:(NSString *)curSelection { 
    self.matchLabel.text = curSelection; 
    //[self refresh]; 
} 

//Did select row in LeftViewController 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSMutableString *s = [[NSMutableString alloc] initWithString:@"Row selected"]; 
    if (_delegate != nil) { 
     [s appendFormat:@" %d ", indexPath.row]; 
     [_delegate matchSelectionChanged:s]; 
    } 
} 

//获取错误 CustomViewTab [1200:11303] *终止应用程序由于未捕获的异常 'NSInvalidArgumentException',原因是: ' - [UINavigationController的matchSelectionChanged:]:无法识别的选择发送到实例0xda6a770' *第一掷调用堆栈: (0x1559052 0x1da8d0a 0x155aced 0x14bff00 0x14bfce2 0x1204e 0x62071d 0x620952 0x25986d 0x152d966 0x152d407 0x14907c0 0x148fdb4 0x148fccb 0x2500879 0x250093e 0x590a9b 0x1df8 0x1d55) 终止叫做抛出异常

我看到didSel调用ectRowAtIndex但是然后RightViewController的matchSelectionChanged:(NSString *)curSelection永远不会被调用。

回答

0

一个老问题的位,但我偶然发现它,一目了然,你有正确的代表?

@interface RightViewController : UIViewController <UISplitViewControllerDelegate> 

我看iOS7所以也许它因为iOS5的

改变