我有一个动态表视图,实际上就像静态的,但我将它设置为动态的,因为它嵌入在视图控制器中。我有一个问题,即表格视图在表格视图委托方法中设置了 3 个单元格的 4 个部分,但我有一个带有字典的数组,准备好填充单元格数据。
正如您在这段代码中看到的那样,它始终在所有部分中设置相同的数据,因为 indexPath.row 用于遍历数组,尽管数组有更多值,但它不会上升到三个。
这是当前代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *jornada = [[NSDictionary alloc] initWithDictionary: [copaReyArray objectAtIndex:indexPath.row]];
self.copaReytable.backgroundColor = [UIColor whiteColor];
if (indexPath.row==0){
cuartosReyCell *headerCell = [tableView dequeueReusableCellWithIdentifier:@"header"];
if (headerCell == nil) {
headerCell = [[ cuartosReyCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"header"];
}
headerCell.cuartos.text = @"1/4 final";
headerCell.backgroundColor = [UIColor colorWithRed:0.008 green:0.235 blue:0.451 alpha:1];
return headerCell;
}
if (indexPath.row==1){
localCopaReyCell *localCell = [tableView dequeueReusableCellWithIdentifier:@"local"];
if (localCell == nil) {
localCell = [[ localCopaReyCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"local"];
}
NSString *equipoLoc = [jornada valueForKey:@"id_local"];
UIImage *img = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",[self applicationDocumentsDirectory],equipoLoc ]];
[localCell.escudo setImage:img];
localCell.escudo.contentMode = UIViewContentModeScaleAspectFit;
localCell.equiLoc.text = [equiposDic valueForKey:equipoLoc];
localCell.equiLoc.textColor = [UIColor colorWithRed:0.004 green:0.29 blue:0.553 alpha:1];
localCell.primerPartido.text = [jornada valueForKey:@"res_local"];
localCell.primerPartido.textColor= [UIColor colorWithRed:0.722 green:0.145 blue:0.345 alpha:1];
return localCell;
}
if (indexPath.row==2){
visitanteCopaReyCell *visitanteCell = [tableView dequeueReusableCellWithIdentifier:@"visitante"];
if (visitanteCell == nil) {
visitanteCell = [[ visitanteCopaReyCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:@"visitante"];
}
NSString *equipoLoc = [jornada valueForKey:@"id_local"];
UIImage *img = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",[self applicationDocumentsDirectory],equipoLoc ]];
[visitanteCell.escudo setImage:img];
visitanteCell.escudo.contentMode = UIViewContentModeScaleAspectFit;
visitanteCell.equiLoc.text = [equiposDic valueForKey:equipoLoc];
visitanteCell.equiLoc.textColor = [UIColor colorWithRed:0.004 green:0.29 blue:0.553 alpha:1];
visitanteCell.primerPartido.text = [jornada valueForKey:@"res_local"];
visitanteCell.primerPartido.textColor= [UIColor colorWithRed:0.004 green:0.29 blue:0.553 alpha:1];
return visitanteCell;
}
我不知道如何正确迭代 copaReyArray 并设置节和行。该数组包含 8 个字典,对应于每个部分(8 个部分,每部分 3 个单元格)。
非常感谢您的帮助。