UI表控件中的部分

时间:2013-02-20 17:53:18

标签: ios objective-c

我在UI表中创建了3个部分View with Different heading(header),现在我将数据直接加载到单元格中,它与section1(indexPath.section == 0)和Section2(indexPath.section == 1)一起工作正常)。但它没有采取section3(indexPath.section == 2)。 任何人都可以告诉我我的错误。

这是守则。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     
 *)indexPath
 {


static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [mainTable dequeueReusableCellWithIdentifier:CellIdentifier];
//  cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];
if (cell == nil)
{




    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    if(indexPath.section == 0)
    {

        cell.textLabel.text = @"Insite  Mobile App Delegate";


        cell.detailTextLabel.text = @"Hi, Make following Changes in";

        cell.textLabel.textColor = [UIColor whiteColor];

        UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, -8, 300, 40)];
        dateLabel.textColor = [UIColor grayColor];
        dateLabel.font = [UIFont systemFontOfSize:12];
        dateLabel.backgroundColor = [UIColor clearColor];
        dateLabel.text = @"Feb 06, 2013";

        [cell addSubview:dateLabel];




    }

    if(indexPath.section == 1)
    {


        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = @"Insite  Mobile App Delegate";

            cell.detailTextLabel.text = @"Hi, Make following Changes in";



        UILabel *titleTextField = [[UILabel alloc]initWithFrame:CGRectMake(10,-10, 300, 40)];
        titleTextField.text = @"Anary, Zubin";
        titleTextField.textColor = [UIColor whiteColor];
        titleTextField.backgroundColor = [UIColor clearColor];
        titleTextField.font = [UIFont boldSystemFontOfSize:16];
        [cell addSubview:titleTextField];



        UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, -8, 300, 40)];
        dateLabel.textColor = [UIColor grayColor];
        dateLabel.font = [UIFont systemFontOfSize:12];
        dateLabel.backgroundColor = [UIColor clearColor];
         dateLabel.text = @"Feb 06, 2013";

        [cell addSubview:dateLabel];

    }


    else if(indexPath.section == 2)
    {


        cell.detailTextLabel.text = @"Daily Mobile Touch Base";
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.text = @"1:00 pm – 1:30 | M1 - 5026 ";
        cell.imageView.image = [UIImage imageNamed:@"iPhone_webx.png"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    cell.imageView.image = [UIImage imageNamed:@"iPhone_webx.png"];


    }






}cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
return cell;
}






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

else if(section==1)
{
    return 3;
}
else if (section==2)
{
       return 3;
}

else
    return 0;
    }

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

1 个答案:

答案 0 :(得分:0)

试试这个

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

UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    if(indexPath.section == 0)
    {
      cell.textLabel.text = @"Insite  Mobile App Delegate";

      cell.detailTextLabel.text = @"Hi, Make following Changes in";
      cell.textLabel.textColor = [UIColor whiteColor];

      UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, -8, 300, 40)];
      dateLabel.textColor = [UIColor grayColor];
      dateLabel.font = [UIFont systemFontOfSize:12];
      dateLabel.backgroundColor = [UIColor clearColor];
      dateLabel.text = @"Feb 06, 2013";
      [cell addSubview:dateLabel];
    }

    if(indexPath.section == 1)
    {
      cell.textLabel.textColor = [UIColor whiteColor];
      cell.textLabel.text = @"Insite  Mobile App Delegate";
      cell.detailTextLabel.text = @"Hi, Make following Changes in";
      UILabel *titleTextField = [[UILabel alloc]initWithFrame:CGRectMake(10,-10, 300, 40)];
      titleTextField.text = @"Anary, Zubin";
      titleTextField.textColor = [UIColor whiteColor];
      titleTextField.backgroundColor = [UIColor clearColor];
      titleTextField.font = [UIFont boldSystemFontOfSize:16];
      [cell addSubview:titleTextField];

      UILabel *dateLabel = [[UILabel alloc]initWithFrame:CGRectMake(180, -8, 300, 40)];
      dateLabel.textColor = [UIColor grayColor];
      dateLabel.font = [UIFont systemFontOfSize:12];
      dateLabel.backgroundColor = [UIColor clearColor];
      dateLabel.text = @"Feb 06, 2013";
      [cell addSubview:dateLabel];
    }
    if(indexPath.section == 2)
    {
      cell.detailTextLabel.text = @"Daily Mobile Touch Base";
      cell.textLabel.textColor = [UIColor whiteColor];
      cell.textLabel.text = @"1:00 pm – 1:30 | M1 - 5026 ";
      cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
      cell.imageView.image = [UIImage imageNamed:@"iPhone_webx.png"];
    }
  cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;  
  return cell;
}