我正在使用加载 UITableView 的菜单样式的幻灯片。- ECSlidingViewController
我在表格视图设置中有大约 7 个单元格,如下所示:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.contentView.backgroundColor = [UIColor colorWithRed:75.0/255.0 green:83.0/255.0 blue:102.0/255.0 alpha:1.0];
UIView *topSplitterBar = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.bounds.size.width, 1)];
topSplitterBar.backgroundColor = [UIColor colorWithRed:62.0/255.0 green:69.0/255.0 blue:85.0/255.0 alpha:1];
[cell.contentView addSubview:topSplitterBar];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor colorWithRed:196.0/255.0 green:204.0/255.0 blue:218.0/255.0 alpha:1];
cell.textLabel.font = [UIFont systemFontOfSize:18.0f];
cell.textLabel.shadowColor = [UIColor colorWithRed:27.0/255.0 green:31.0/255.0 blue:41.0/255.0 alpha:1];
cell.textLabel.shadowOffset = CGSizeMake(0, 1);
UIView *selectedBg = [[UIView alloc] initWithFrame:cell.frame];
selectedBg.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1];
cell.selectedBackgroundView = selectedBg;
如果这是当前显示的控制器,那么将单元格显示为 selectedBg 的最佳方法是什么?
例如,我可以访问以下内容:
if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) {
但是,我不确定在哪里进行设置是最佳实践?我可以在开关盒中进行单元标签设置...例如:
switch ( indexPath.row ) {
case 0: {
if ([self.slidingViewController.topViewController isKindOfClass:[MESHomeViewController class]]) {
cell.contentView.backgroundColor = [UIColor colorWithRed:50.0/255.0 green:56.0/255.0 blue:73.0/255.0 alpha:1];
}
cell.textLabel.text = NSLocalizedString(@"LMGames", @"Left Menu - Games");
break ;
但是,当从菜单中选择一个新项目时,我每次都需要重新加载表格,这样好吗?self.tableView reloadData
每次选择一个单元格时完成,还是有更好的方法来解决这个问题?