gpt4 book ai didi

ios - 我想对 UITableView 中的行进行编号

转载 作者:行者123 更新时间:2023-11-29 04:47:04 27 4
gpt4 key购买 nike

我使用核心数据,每当我将问题添加到表中时,我有一个名为问题的实体,我希望它们显示问题的编号(有点像自动增量的东西)有人可以帮我吗谢谢

这是我的代码(如果相关)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

// Return the number of rows in the section.
return [self.questionArray count];
}

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


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];


// Configure the cell...

questionObject = [self.questionArray objectAtIndex:indexPath.row];

cell.textLabel.text = questionObject.questionDescription;


return cell;
}

最佳答案

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


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (nil == cell) {
cell = ...; //create a cell instance if it wasn't found in reusable cache
}

// Configure the cell...

questionObject = [self.questionArray objectAtIndex:indexPath.row];

NSString *cellText = [NSString stringWithFormat:@"%d. %@", indexPath.row+1, questionObject.questionDescription];
cell.textLabel.text = cellText;


return cell;
}

关于ios - 我想对 UITableView 中的行进行编号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9479774/

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