Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to set ViewController's title in Delegate method
    text
    copied!<p>I have implemented an optionTable with stores a list of options for my app to execute</p> <p>I have defined a protocol method within the option table so that the main table knows when the user has selected an option</p> <pre><code>//Protocol defined in **OPTIONSTABLEVIEW** @protocol OptionsTableDelegate &lt;NSObject&gt; -(void)didSelectOption:(NSString *)option withtitleString:(NSString*)titleString; @end //Set the delegate property @interface OptionsTableView : UITableView &lt;UITableViewDataSource,UITableViewDelegate&gt; { id optionTableDelegate; } @end </code></pre> <p>This delegate method is triggered after the user selects an option in the optionstableview</p> <pre><code>//User selects an option and the delegate method is triggered - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { switch (indexPath.row) { case OPTION_LATEST: self.option = @"for_you"; self.titleString = [self.optionsArray objectAtIndex:OPTION_LATEST]; break; case OPTION_RANDOM: self.option = @"random"; self.titleString = [self.optionsArray objectAtIndex:OPTION_RANDOM]; break; default: break; } //Delegate method triggered to return the option and title string to the main table [self.optionTableDelegate didSelectOption:self.option withtitleString:self.titleString]; } </code></pre> <p>In the main table (calling options table) I setup the options table delegate to self and also included the delegate method</p> <pre><code>//Main table **QUESTIONTABLEVIEWCONTROLLER** - (void)viewDidLoad { [super viewDidLoad]; //Set up options tableview self.optionsTableHeight = 24 + (44*2); CGRect optionsTableFrame = CGRectMake(0, -optionsTableHeight, 320, optionsTableHeight); OptionsTableView *tempOptionsTable = [[OptionsTableView alloc]initWithFrame:optionsTableFrame style:UITableViewStyleGrouped]; self.optionsTableView = tempOptionsTable; //Setting the delegate to self self.optionsTableView.optionTableDelegate = self; [self.view addSubview:self.optionsTableView]; } </code></pre> <p>And I tried to set the page title in the delegate method of the main table</p> <pre><code>//Delegate method in main table -(void)didSelectOption:(NSString *)option withtitleString:(NSString *)titleString { //Set title here (doesn't work) self.title = titleString; NSLog(@"title :%@",self.title); self.type = option; [self.optionsTableView slideOptionsTableOut]; [self getData]; } </code></pre> <p>The title of my page doesn't get change in the above delegate method. Any advise on how I can change the title after selecting the option in the options table?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload