【问题标题】:didSelectRowAtIndexPath - colorText change not updated instantaneouslydidSelectRowAtIndexPath - colorText 更改不会立即更新
【发布时间】:2014-02-15 21:22:42
【问题描述】:

我正在尝试更改自定义 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 以使其显示后立即运行什么方法?

【问题讨论】:

    标签: cocoa-touch uilabel didselectrowatindexpath


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-11-08
      • 2013-10-11
      • 1970-01-01
      • 2022-09-28
      • 2012-09-22
      • 1970-01-01
      • 1970-01-01
      • 2016-09-10
      • 1970-01-01
      相关资源
      最近更新 更多