gpt4 book ai didi

ios - 如何在 tableview iOS 中设置节标题而不重复数据?

转载 作者:行者123 更新时间:2023-11-29 01:11:33 24 4
gpt4 key购买 nike

我有一个 TableView ,现在我正在初始化表,

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [arr count]+1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [arr count]+1;
}

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

NSUInteger row = [indexPath row];
if (row == 0)
{
UITableViewCell *cell = [[UITableViewCell alloc] init];
return cell;
}
else
{
static NSString *CellIdentifier = @"moduleCell";
MyTableViewCell *cell = (MyTableViewCell*)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];

if (cell == nil)
{

NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];

cell.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

}
current = [arr objectAtIndex:indexPath.row-1];
[cell setCellDetails:arr WithIndex:row-1 withParentView:self];
return cell;
}
}

当我在我的表格 View 中重复执行此数据时。在我这样做之前,我做了,

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

这是有效的,但我需要设置像标题这样的节标题。那么有没有办法设置section headers而不重复数据呢?

最佳答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0){//for first section

}else if(indexPath.section == 1){//for second section

}
}

关于ios - 如何在 tableview iOS 中设置节标题而不重复数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35692425/

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