【发布时间】:2012-04-09 03:07:46
【问题描述】:
我有一个带有 UISplitViewConroller 的通用应用程序。我正在使用故事板。
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 0x15550 x14bff00 0x14bff00 0x14bfce2 0x1204e 0x62071d 0x1120952 0x152d407 0x152d407 0x152d407 0x152d407 0x14907c0 0x14807c0 0x148fdb4 0x148fdb4 0x148fccb 0x2500879 0x2500930 0x590a9b 0x1df8 0x1d55) 终止称为抛出异常
我看到 didSelectRowAtIndex 被调用,但 RightViewController 的 matchSelectionChanged:(NSString *)curSelection 从未被调用。
【问题讨论】: