iOS--tableview分组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (section == 0) {
        return 4;
    }else{
        return 2;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 20.0;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *reuseIdentifier= @"reuseIdentifier";
    PersonalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil) {
        cell = [[PersonalTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
    }
    
    
    
    
    switch (indexPath.section) {
        case 0:{
            
            if (indexPath.row == 0) {
                
                cell.leftImg.image = [UIImage imageNamed:@"sjq_home20.png"];
                
                cell.nameLabel.text = @"图文";
                
            }else if(indexPath.row == 1){
                
                cell.leftImg.image = [UIImage imageNamed:@"sjq_readMode2.png"];
                
                cell.nameLabel.text = @"文章";
                
            }else if(indexPath.row == 2){
                
                cell.leftImg.image = [UIImage imageNamed:@"sjq_music2.png"];
                
                cell.nameLabel.text = @"歌单";
            }else{
                cell.leftImg.image = [UIImage imageNamed:@"sjq_movice2.png"];
                
                cell.nameLabel.text = @"电影";
            }
        }
            break;
            
        case 1:{
            
            if (indexPath.row == 0) {
                
                cell.leftImg.image = [UIImage imageNamed:@"nightType.png"];
                
                UISwitch *switchview = [[UISwitch alloc] initWithFrame:CGRectZero];
                [switchview addTarget:self action:@selector(updateSwitchAtIndexPath:) forControlEvents:UIControlEventValueChanged];
                cell.accessoryView = switchview;
                switchview.on = [User moodsession];
                //指定开关两种状态下背景颜色和滑动杆颜色
                [[UISwitch appearance] setOnTintColor:[UIColor colorWithRed:81/255.0 green:81/255.0 blue:81/255.0 alpha:1]];
                
                cell.nameLabel.text = @"夜间模式";
                
            }else if(indexPath.row == 1){
                
                cell.leftImg.image = [UIImage imageNamed:@"otherShezhi.png"];
                
                cell.nameLabel.text = @"其他设置";
                
                
                
            }
        }
            break;
            
        default:
            break;
    }
    
    if ([User moodsession]) {
        cell.backgroundColor = [UIColor colorWithRed:61/255.0 green:61/255.0 blue:61/255.0 alpha:1];
        cell.nameLabel.textColor = [UIColor colorWithRed:126/255.0 green:126/255.0 blue:126/255.0 alpha:1];
        self.tableview.backgroundColor = [UIColor grayColor];
        
    }else{
        cell.backgroundColor = [UIColor whiteColor];
        self.tableview.backgroundColor = [UIColor whiteColor];
        cell.nameLabel.textColor = [UIColor blackColor];
    }
    
    
    
    cell.textLabel.font = [UIFont systemFontOfSize:19];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.section) {
        case 0:{
            
            if (indexPath.row == 0) {
                PersonTuWenViewController *PersonTuWenView = [self.storyboard instantiateViewControllerWithIdentifier:@"PersonTuWenView"];
                PersonTuWenView.charidFromTop = self.loginUser.userId;
                [self.navigationController pushViewController:PersonTuWenView animated:YES];
                
            }else if(indexPath.row == 1){
                
                
            }else if(indexPath.row == 2){
                
                
            }else if(indexPath.row == 3){
                
                
            }
        }
            break;
            
        case 1:{
            
            if (indexPath.row == 0) {
                
                
                
            }else{
                
                QiTasetViewController *qitaset = [self.storyboard instantiateViewControllerWithIdentifier:@"qitaset"];
                [self.navigationController pushViewController:qitaset animated:YES];
            }
        }
            break;
            
        default:
            break;
    }
    
    
}

效果图:

posted on 2017-01-09 17:24  麦芽呀~  阅读(258)  评论(0编辑  收藏  举报