gpt4 book ai didi

ios - for 循环的最后一条记录在每个 Cell forRowAtIndexPath 处重复

转载 作者:行者123 更新时间:2023-11-29 00:42:32 26 4
gpt4 key购买 nike

这里的小错误可能是愚蠢的。我正在从文档目录中读取文件。我根据特定键的值过滤结果。以及我在 UITableView 中呈现的特定值内具有特定字符串的任何内容。行数已正确填充,但 cell.textLabel.text 未在每个单元格 rowForAtIndexPath 处显示正确的名称。我的问题是,我是否正确地迭代了我的循环?由于 indexPath,我是否错误地设置了 textLabel?我附上了输出的屏幕截图和 NSLog 语句,显示了该特定对象的假定 indexPath。下面是显示 RowAtIndexPath 的 willDisplayCell 的代码片段。

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row%2 == 0) {
UIColor *altCellColor = [UIColor colorWithWhite:0.7 alpha:0.2];
cell.backgroundColor = altCellColor;
}

for (int objectToDisplay = 0; objectToDisplay<[tableDataSourceArray count]; objectToDisplay++) {
NSLog(@"%lu", (unsigned long)objectToDisplay);
NSString *objectTitle = [[tableDataSourceArray objectAtIndex:objectToDisplay] valueForKey:@"ConnectabilityObjectTitle"];
NSString *pingResult = [[tableDataSourceArray objectAtIndex:objectToDisplay] valueForKey:@"ConnectivityPingTestResultValue"];
NSString *portConnectResult = [[tableDataSourceArray objectAtIndex:objectToDisplay] valueForKey:@"ConnectivityPortConnectResultValue"];

if ([pingResult containsString:@"Successful"]) {
if ([portConnectResult isEqualToString:@"Successful"]) {
} else {
cell.textLabel.text = objectTitle;

cell.detailTextLabel.text = @"Failed to connect to port for this server/service";
NSLog(@"%@ at row %lu", objectTitle, (unsigned long)objectToDisplay);
}
} else {
cell.textLabel.text = objectTitle;
cell.detailTextLabel.text = @"Failed to ping this server/service";
}
}
}

这是来自控制台的 NSLogStatement。

2016-08-23 11:04:11.509 FlightPath[1346:551416] 0
2016-08-23 11:04:11.510 FlightPath[1346:551416] 1
2016-08-23 11:04:11.510 FlightPath[1346:551416] 2
2016-08-23 11:04:11.510 FlightPath[1346:551416] 3
2016-08-23 11:04:11.510 FlightPath[1346:551416] 4
2016-08-23 11:04:11.511 FlightPath[1346:551416] 5
2016-08-23 11:04:11.513 FlightPath[1346:551416] Store Drive at row 5
2016-08-23 11:04:11.513 FlightPath[1346:551416] 6
2016-08-23 11:04:11.514 FlightPath[1346:551416] 7
2016-08-23 11:04:11.514 FlightPath[1346:551416] 8
2016-08-23 11:04:11.514 FlightPath[1346:551416] 9
2016-08-23 11:04:11.515 FlightPath[1346:551416] 10
2016-08-23 11:04:11.515 FlightPath[1346:551416] 11
2016-08-23 11:04:11.515 FlightPath[1346:551416] 12
2016-08-23 11:04:11.517 FlightPath[1346:551416] 13
2016-08-23 11:04:11.517 FlightPath[1346:551416] 14
2016-08-23 11:04:11.517 FlightPath[1346:551416] 15
2016-08-23 11:04:11.518 FlightPath[1346:551416] 16
2016-08-23 11:04:11.518 FlightPath[1346:551416] 17
2016-08-23 11:04:11.518 FlightPath[1346:551416] 18
2016-08-23 11:04:11.518 FlightPath[1346:551416] 19
2016-08-23 11:04:11.519 FlightPath[1346:551416] 20
2016-08-23 11:04:11.519 FlightPath[1346:551416] 21
2016-08-23 11:04:11.519 FlightPath[1346:551416] 22
2016-08-23 11:04:11.522 FlightPath[1346:551416] 23
2016-08-23 11:04:11.522 FlightPath[1346:551416] 24
2016-08-23 11:04:11.522 FlightPath[1346:551416] StorewebP at row 24
2016-08-23 11:04:11.523 FlightPath[1346:551416] 25
2016-08-23 11:04:11.523 FlightPath[1346:551416] 26
2016-08-23 11:04:11.523 FlightPath[1346:551416] FIM DataCenter VIP at row 26
2016-08-23 11:04:11.524 FlightPath[1346:551416] 27

这是截图。 TableViewDuplicateOfLastRecordIssue

最佳答案

从您的代码中删除 for 循环。
因为它总是会在你的 datasourceArray 中分配最后一个值并使用

[tableDataSourceArray objectAtIndex:indexPath.row]

代替

[tableDataSourceArray objectAtIndex:objectToDisplay]

关于ios - for 循环的最后一条记录在每个 Cell forRowAtIndexPath 处重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39104843/

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