1

I have a Universal app with UISplitViewConroller. I am using storyboards.

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; 
}

I have a left and right controller for UISplitViewController app.

LeftViewController has a custom delegate, which is set as 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 implements this delegate protocol. However, when cell inside row is clicked in LeftViewController the delegates failing.

//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]; 
    }
}

//Get error CustomViewTab[1200:11303] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINavigationController matchSelectionChanged:]: unrecognized selector sent to instance 0xda6a770' * First throw call stack: (0x1559052 0x1da8d0a 0x155aced 0x14bff00 0x14bfce2 0x1204e 0x62071d 0x620952 0x25986d 0x152d966 0x152d407 0x14907c0 0x148fdb4 0x148fccb 0x2500879 0x250093e 0x590a9b 0x1df8 0x1d55) terminate called throwing an exception

I see didSelectRowAtIndex called but then RightViewController's matchSelectionChanged:(NSString *)curSelection never gets called.

4

1 に答える 1