REFrostedViewController设置菜单项的选择

时间:2018-01-15 06:18:02

标签: ios objective-c

我想在不同菜单项之间切换时设置具有一些背景颜色的表格视图单元格的选择。

我正在使用REFrostedViewController库。

以下是我REFrostedViewController的菜单控制器代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.opaque = NO;
    self.tableView.backgroundColor = [UIColor whiteColor];
    [self.tableView sizeToFit];
}

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundColor = [UIColor whiteColor];
    cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.font = [UIFont systemFontOfSize:15];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NavigationVC *navigationController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentController"];

            switch (indexPath.row) {
                case 0: {
                    // Push view controller 1
                }
                    break;

                case 1: {
                    // Push view controller 2
                }

                    break;
            }
}

1 个答案:

答案 0 :(得分:0)

修改setSelected:animated:这样的UITableViewCell方法

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    UIView * selectedBackgroundView = [[UIView alloc] init];
    [selectedBackgroundView setBackgroundColor:[Utility greenColor]]; // set color here
    [self setSelectedBackgroundView:selectedBackgroundView];
}

然后从didSelectRowAtIndexPath委托调用此方法或在willDisplayCell上实施。