开发者

Split View Application, how to call a function that is situated in root view?

开发者 https://www.devze.com 2023-03-27 23:43 出处:网络
I\'m making an split-view application. In RootController there is a function to to the next cell of the tableview:

I'm making an split-view application. In RootController there is a function to to the next cell of the tableview:

-(void)goToNextCell
{
    NSIndexPath *nextCell = [NSIndexPath indexPathForRow:currentSelection.row+1 inSection:curren开发者_StackOverflowtSelection.section];

    [self.tableView selectRowAtIndexPath:nextCell animated:YES scrollPosition: UITableViewScrollPositionTop];
    NSLog(@"Went to next Cell!");
}

And in the detailed view a have button NEXT to go to the next cell:

-(IBAction)goToNextTextClicked:(id)sender
{
    //Should call this function ^^^^ HOW?(((    
}


I have typically done this kind of thing by defining a delegate protocol within my detail view controller class header like this:

@protocol DetailViewControllerDelegate
- (void)didClickGoToNext;
@end

@interface DetailViewController {
    id<DetailViewControllerDelegate> delegate;
}

@property (nonatomic, assign) id<DetailViewControllerDelegate> delegate;
@end

In my implementation of the detailed view controller I would then have:

-(IBAction)goToNextTextClicked:(id)sender {
    [delegate didClickGoToNext];
}

Finally, I would have by root view controller implement the DetailViewControllerDelegate protocol and set itself as the delegate. The root view controller now will be notified when the detail view controller's button has been pressed, and it can react accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消