[英]Unable to set ViewController's title in Delegate method
I have implemented an optionTable with stores a list of options for my app to execute 我已经实现了一个optionTable,其中存储了我的应用程序要执行的选项列表
I have defined a protocol method within the option table so that the main table knows when the user has selected an option 我已经在选项表中定义了协议方法,以便主表知道用户何时选择了选项
//Protocol defined in **OPTIONSTABLEVIEW**
@protocol OptionsTableDelegate <NSObject>
-(void)didSelectOption:(NSString *)option withtitleString:(NSString*)titleString;
@end
//Set the delegate property
@interface OptionsTableView : UITableView <UITableViewDataSource,UITableViewDelegate>
{
id optionTableDelegate;
}
@end
This delegate method is triggered after the user selects an option in the optionstableview 用户在optionstableview中选择一个选项后,将触发此委托方法
//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];
}
In the main table (calling options table) I setup the options table delegate to self and also included the delegate method 在主表(调用选项表)中,我将选项表委托设置为self,还包括了委托方法
//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];
}
And I tried to set the page title in the delegate method of the main table 我试图在主表的委托方法中设置页面标题
//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];
}
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?
关于在选项表中选择选项后如何更改标题的任何建议?
You can use [self.navigationItem setTitle:@"Your Title"];
您可以使用
[self.navigationItem setTitle:@"Your Title"];
to update the title of your navBar. 更新navBar的标题。
Try to make one of two: 尝试使两个之一:
1) Replace [self.optionTableDelegate didSelectOption:self.option withtitleString:self.titleString];
1)用
[self.optionTableDelegate didSelectOption:self.option withtitleString:self.titleString];
替换[self.optionTableDelegate didSelectOption:self.option withtitleString:self.titleString];
with [self didSelectOption:self.option withtitleString:self.titleString];
与
[self didSelectOption:self.option withtitleString:self.titleString];
2) Replace self.optionsTableView.optionTableDelegate = self;
2)替换
self.optionsTableView.optionTableDelegate = self;
with self.optionTableDelegate = self;
与
self.optionTableDelegate = self;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.