Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UI表控件中的节_Ios_Objective C - Fatal编程技术网

Ios UI表控件中的节

Ios UI表控件中的节,ios,objective-c,Ios,Objective C,我在UI表视图中创建了3个不同标题(header)的部分,现在我直接将数据加载到单元格中,第1部分(indepath.section==0)和第2部分(indepath.section==1)工作正常。但它不使用第3节(indexPath.section==2)。 谁能告诉我我的错误吗 这是代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)in

我在UI表视图中创建了3个不同标题(header)的部分,现在我直接将数据加载到单元格中,第1部分(indepath.section==0)和第2部分(indepath.section==1)工作正常。但它不使用第3节(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;}
试试这个

- (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;
}

为什么要检查
单元格==nil
?检查numberOfSectionsInTableView:dataSourceMethod,它返回3?嗨,你能分享你的
numberOfSectionsInTableView
代码吗?您是否尝试过调试
if(indexPath.section==2)
代码以确保您的代码正在执行?如果不是,可能是因为您只指定了2个部分,而不是3个。另外,我的第一部分和第三部分是相同的,而不是使用If-else条件use switch case来工作FasterOpe相同的故事。应该有什么区别?修复了,谢谢,您的代码