didSelectRowAtIndexPath - colorText 更改不会立即更新
Posted
技术标签:
【中文标题】didSelectRowAtIndexPath - colorText 更改不会立即更新【英文标题】:didSelectRowAtIndexPath - colorText change not updated instantaneously 【发布时间】: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 以使其显示后立即运行什么方法?
【问题讨论】:
【参考方案1】:检查 UILabel 的 highlightedTextColor 属性。这是更改所选单元格标签颜色的正确方法。
【讨论】:
以上是关于didSelectRowAtIndexPath - colorText 更改不会立即更新的主要内容,如果未能解决你的问题,请参考以下文章
didSelectRowAtIndexPath 没有被调用?
tableView - didSelectRowAtIndexPath 未调用