0

テーブルに 3 つのセクションがあるので、セクション 1 (行 2 と 3) のタイトル セルにのみ値を割り当てて、タイトルが次のセクションに表示され、すべてのセルにジャンプするようにします。それを解決するのを手伝ってください!ここに私のコードがあります:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        //------------ Customise lable and image in cell ----------------------
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        self.nameModuleLable = [[UILabel alloc] initWithFrame:CGRectMake(35, 5, 80, 30)];
        self.nameModuleLable.font = [UIFont systemFontOfSize:13];
        self.nameModuleLable.textColor = [UIColor whiteColor];
        self.nameModuleLable.tag = 1;

        self.nuberOfMessLable = [[UILabel alloc] initWithFrame:CGRectMake(200, 0, 40, 40)];
        self.nuberOfMessLable.font = [UIFont systemFontOfSize:13];
        self.nuberOfMessLable.textColor = [UIColor whiteColor];
        self.nuberOfMessLable.tag = 2;

        self.cellimageView = [[UIImageView alloc] init];
        self.cellimageView.frame = CGRectMake(8, 11, 20, 20);
        self.cellimageView.tag = 3;

        [cell addSubview:self.nameModuleLable];
        [cell addSubview:self.cellimageView];
        [cell addSubview:self.nuberOfMessLable];

    }
    self.nameModuleLable = (UILabel*)[cell viewWithTag:1];
    self.nuberOfMessLable = (UILabel*)[cell viewWithTag:2];
    self.cellimageView = (UIImageView*)[cell viewWithTag:3];

    // -------------Number of section in cell 2 and 3 in section 0-----------
    if (indexPath.section == 0) {
        if (indexPath.row == 2) {
            if (!numberOfMessage) {
                self.nuberOfMessLable.text = @"0";
            } else {
                self.nuberOfMessLable.text = [NSString stringWithFormat:@"%d",numberOfMessage];
            }
        }

        else if (indexPath.row == 3) {
            if (!numberOfFriend) {
                self.nuberOfMessLable.text = @"0";
            } else {
                self.nuberOfMessLable.text = [NSString stringWithFormat:@"%d",numberOfFriend];
            }
        }
        //-------------------Assign value for home's menu------------------------------
        self.nameModuleLable.text = [home objectAtIndex:indexPath.row];
        self.cellimageView.image = [UIImage imageNamed:[homeImage objectAtIndex:indexPath.row]];
        //--------------------------Assign value for application's menu--------------------------
    } else if (indexPath.section == 1){
        Module *currentModule = [self.moduleArray objectAtIndex:indexPath.row];
        self.nameModuleLable.text = [currentModule valueForKey:@"mName"];
        NSString *avaImageString = [currentModule valueForKey:@"mImage"];
        NSURL *urlAva = [NSURL URLWithString:avaImageString];
        NSData *dataAva = [NSData dataWithContentsOfURL:urlAva];
        self.cellimageView.image = [UIImage imageWithData:dataAva];
        //---------------------------Logout section---------------------------------
    } else if (indexPath.section == 2) {
        self.nameModuleLable.text = [logout objectAtIndex:indexPath.row];
        self.cellimageView.image = [UIImage imageNamed:[logoutImage objectAtIndex:indexPath.row]];
    }

    return cell;
}
4

1 に答える 1