0

アプリが実行するオプションのリストを格納する optionTable を実装しました

ユーザーがいつオプションを選択したかをメインテーブルが認識できるように、オプションテーブル内にプロトコルメソッドを定義しました

//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

このデリゲート メソッドは、ユーザーが 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];
}

メイン テーブル (オプション テーブルの呼び出し) で、オプション テーブルのデリゲートを自分自身にセットアップし、デリゲート メソッドも含めました。

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

そして、メインテーブルのデリゲートメソッドにページタイトルを設定してみました

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

}

私のページのタイトルは、上記のデリゲート メソッドでは変更されません。オプション表でオプションを選択した後にタイトルを変更する方法について何かアドバイスはありますか?

4

2 に答える 2

0

次の 2 つのいずれかを作成してみてください。

[self.optionTableDelegate didSelectOption:self.option withtitleString:self.titleString];1)と置き換えます[self didSelectOption:self.option withtitleString:self.titleString];

2)self.optionsTableView.optionTableDelegate = self;に置き換えるself.optionTableDelegate = self;

于 2011-10-06T07:21:50.307 に答える