简体   繁体   中英

Getting reference to a View controller which is generated by a container view.

I am new to iOS application Development.

For my project I am triggering a View Controller from a Table View Cell (say implementation/interface file name People) using performSegueWithIdentifier. Now in the view controller (say ReportViewController) generated I have used a container view to display the person's name which was clicked, in the People table view cell of course. What I am doing is trying to fire a segue in didSelectRowAtIndexPath method and writing the following code in prepareforsegue. But the title is not being displayed.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"reportgenerator"]){
        ReportViewController *controller = (ReportViewController *)segue.destinationViewController;
        ReportsTitleViewController *titleView = (ReportsTitleViewController *)controller.titleContainer;
        titleView.topLabel = [currentCellContents.name stringByAppendingString:[NSString stringWithFormat:@" %d",indices.row ]];
    }
} 

toplabel is a string and in the viewdidload method of ReportsTitleViewController I have set the label to this string. currentCellContents is the object of class storing the data and I am also printing the index of the place which was selected (for the time being).

Try initializing it like so:

ReportViewController *controller = [segue destinationViewController];
ReportsTitleViewController *titleView = controller.titleContainer;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM