我在 UI 表格视图中创建了 3 个具有不同标题(标题)的部分,现在我直接将数据加载到单元格中,它与 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;}