gpt4 book ai didi

ios - 如何在每几个 TableView 单元格之间添加条形图

转载 作者:行者123 更新时间:2023-11-28 20:28:24 25 4
gpt4 key购买 nike

我想创建一个如下所示的 tableView。 (嗯,有不同的标题 ;))

enter image description here

到目前为止,我在一些应用程序中看到了这些,但我不知道如何制作它们。由于色调(如导航栏)和各种应用程序中的相似外观,我猜这些不是自定义单元格,而是不同的东西。

还有一个问题(如果它们是自定义单元格)。当我在 Storyboard表格 View 中更改原型(prototype)单元格的单元格高度/背景时,它不会显示在应用程序中,直到我为它创建一个额外的自定义单元格类。我错过了什么?

if (indexPath.row == 0 || indexPath.row == 7)
{
static NSString *CellIdentifier = @"TitleCell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//heigh does not change -.-
if (cell1 == nil){
cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
return cell1;
}
else {
static NSString *CellIdentifier = @"FirstCell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell1 == nil){
cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell1.textLabel.text = [[articles objectAtIndex:indexPath.row]objectForKey:labelkey1];

最佳答案

它们是节标题。

您可以通过添加此方法来添加节标题:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"My title";
}

要添加多个部分,您需要通过以下方法传递合适的值:

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

传递每个部分的行数:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}

从上面的代码中,您将获得 7 个部分,每个部分有 2 行。您需要相应地处理部分、行及其数据。

tableView:titleForHeaderInSection:

Asks the data source for the title of the header of the specified section of the table view. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section Parameters

tableView

The table-view object asking for the title.  section

An index number identifying a section of tableView .

Return Value

A string to use as the title of the section header. If you return nil , the section will have no title. Discussion

The table view uses a fixed font style for section header titles. If you want a different font style, return a custom view (for example, a UILabel object) in the delegate method tableView:viewForHeaderInSection: instead. Availability

Available in iOS 2.0 and later.

See Also

– tableView:titleForFooterInSection:

Declared In UITableView.h

引用:

  1. > UITableViewDataSource
  2. > UITableView

关于ios - 如何在每几个 TableView 单元格之间添加条形图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13217750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com