2016-12-07 17 views
0

ビデオプログラムリストを含むテーブルビューがあります。私がプログラムをタップすると、そのプログラムはそのテーブルビューの上のプレーヤーの視点で再生されます。それはこのように見えます。私はその行のテキストが赤の色を変えたい行をタップした後、私が何をしたいのかイベントが発生した後にUITableViewCellのテキストの色を変更しました。

enter image description here

です。私の問題は、瞬時に赤に変わることはできませんが、その行のテーブルビューをスクロールして画面外に戻し、再び画面に戻って、選択した行のテキストが赤になる必要があります。私はこれがテーブルビューcellForRowAtIndexPathの動作であることを知っています。だから私はテーブルビューdidSelectRowAtIndexPath[self.tableView reloadData]を追加しますが、動作しません。私が言ったように、私は選択されたロールを画面からスクロールし、画面上に戻ってその色を変えなければなりません。どうすれば問題を解決できますか?

以下は関連コードです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"LiveTableViewCell"; 

    LiveTableViewCell *cell = (LiveTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    //...... (more stuff here but not related) 

    //Color - for one selected/playing 
    if (programList.programId == self.liveData.programId) { 
     [str1 addAttribute:NSStrikethroughColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color 
     [str1 addAttribute:NSForegroundColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color 
    } 

    cell.title.attributedText = str1; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    //...... (more stuff here but not related) 
    [self.tableView reloadData]; 
} 
+0

私はあなたがチェックしてセルの色を設定しなかった気づいたところではそのindexPathは、あなたが定義し更新したいくつかの値を持ちます。これらのIDを更新するコードは、tableView didSelectRowAtIndexPathの後に実行できますか? –

答えて

1

最も簡単なことは、セルを独自のメソッドに設定するロジックを抽出することです。次に、あなたのcellForRowAtIndexPathとdidSelect方法は同じ方法に

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"LiveTableViewCell"; 

    LiveTableViewCell *cell = (LiveTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    //...... (more stuff here but not related) 
    [self configureCell:cell withProgramList:programList]; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    //...... (more stuff here but not related) 

    LiveTableViewCell *cell = (id)[tableView cellForRowAtIndexPath:indexPath]; 
    ProgramList *programList = // get programList at indexpath 
    [self configureCell:cell withProgramList:programList]; 
} 

- (void)configureCell:(LiveTableViewCell *)cell withProgramList:(ProgramList *)programList { 
    //Color - for one selected/playing 
    if (programList.programId == self.liveData.programId) { 
     [str1 addAttribute:NSStrikethroughColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color 
     [str1 addAttribute:NSForegroundColorAttributeName value:[CustomColor textColorf45160] range:strRange1]; //red color 
    } 

    cell.title.attributedText = str1; 
} 
0

を通じ呼び出すことができますあなたの「self.tableViewは」「didSelectRowAtIndexPath」で「のtableView」と同じでなければなりません。

を使用でき
0

- (無効)にtableView:(のUITableView *)のtableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPathデリゲート関数を次のように:

(void)tableView:(UITableView *)tableView 
didHighlightRowAtIndexPath:(NSIndexPath *)indexPath{ 

    LiveTableViewCell *cell = (LiveTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    cell.title.textColor = UIColor.redColor; 


} 
関連する問題