次の実装があります。ここでは、customcellとしてフッタービューを追加しています。しかし、コンテンツがなければ、私はそれを表示したい場合は、最後のセルを表示したくありません。TableViewでカスタムセルを非表示にする
現在の実装では、常に最後のセルが表示されます。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [self.adminOrderElements count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return adminOrderElements[section].products.count + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row < adminOrderElements[indexPath.section].products.count)
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSArray * tempArray = adminOrderElements[indexPath.section].products;
cell.textLabel.text = [[tempArray objectAtIndex:indexPath.row] objectForKey:@"productname"];
return cell;
}
else
{
static NSString *CellIdentifier = @"FooterCell";
FooterTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[FooterTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
if(adminOrderElements[indexPath.section].expanded && [adminOrderElements[indexPath.section].notes length]>0)
{
cell.footerLabel.text = [NSString stringWithFormat:@"Notes: %@", adminOrderElements[indexPath.section].notes];
}
else
{
cell.heightConstraints.constant = 1;
cell.footerLabel.text = @"";
}
return cell;
}
}
カスタムセルを確認するにはどうすればよいですか? – hotspring
このメソッドを実装するだけです。 – Nirmalsinh
特定の配列インデックスのコンテンツを取得しない場合は、条件を設定する必要があります。その後、高さを0にできます。 – Nirmalsinh