didSelectRowAtIndexPath - colorText更改未立即更新

时间:2014-02-15 21:22:43

标签: cocoa-touch uilabel didselectrowatindexpath

我正在尝试更改自定义UITableViewCell中自定义标签中的文本颜色。

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

{

//////////////////////
// Unselect the prevoius selected Cell and select this one
WSLanguageTableViewCell *aPreviousSelectedCell=  (WSLanguageTableViewCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:selectedRow inSection:0]];
aPreviousSelectedCell.languageLabel.textColor = [UIColor lightGrayColor];

// Select the new one
WSLanguageTableViewCell *aSelectedCell = (WSLanguageTableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
aSelectedCell.languageLabel.textColor = [UIColor colorLanguageCellLanguageLabelText];

selectedRow = indexPath.row;


///////////////////////
// Get the new language
PFObject* languageObject = [self.objects objectAtIndex:indexPath.row];
NSString* language = [languageObject objectForKey:kWSLanguageNameKey];


//////////////////////
// Check if it's setup -- if not, then show alert
if (![[languageObject objectForKey:kWSLanguageIsSetupKey] boolValue]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:kPromptChangeLanguageNotSetup message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
    [alert show];

    return;
}


//////////////////////
// Check if it's the current language -- only change if not
if (![language isEqualToString:[[WSWordlistManager shared] languageTarget]]) {


    // Show HUD view
    AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
    [appDel showGlobalProgressHUDWithTitle:kLocalizedChangingLanguage];


    //////////////////////
    // Load the wordlist
    [[WSWordlistManager shared] loadWordlist:language completion:^() {


        //////////////////////
        // Add the language to user (and vice versa) in DB
        [WSUserManager addLanguage:language forUser:[PFUser currentUser]];


        ///////////////////
        // Reload User Words
        WSDatabaseManager* databaseManager = [[WSDatabaseManager alloc] init];
        [databaseManager retrieveUserWordlistForCurrentUserWithCallback:^(NSError *error) {


            // Dismiss the HUD
            AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication]delegate];
            [appDel dismissGlobalHUD];


            // Navigate to root
            [self.navigationController popToRootViewControllerAnimated:YES];

        }];

    }];        
}

}

问题是,颜色变化会延迟一段时间。如果我取出设置两个单元格的textColor的6行以下的所有内容,则更改是瞬时的。更改textColor后我会立即运行什么方法,以便显示?

1 个答案:

答案 0 :(得分:0)

检查UILabel的highlightedTextColor属性。这是更改所选单元格标签颜色的正确方法。