我用自定义UITableViewCell有一个UITableView问题。 该表由一个NSArray填充,我希望如果此NSArray中的某个对象以 - 开头 - 改变其外观。根据内容更改单个UITableViewCell的外观
问题是,以 - 开头的UITableViewCell发生了变化,但也会更改其他不应更改的单元格。
这是我的代码:
//this is the way in which change the height of the cell if the object in the array begins with -
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *try = [arrayTitleEs objectAtIndex:indexPath.row];
if ([[try substringToIndex:1]isEqualToString:@"-"]) {
return 45;
}
else return 160;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellCardioScheda";
CardioSchedaCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.titleEs.text = [arrayTitoloEs objectAtIndex:indexPath.row];
NSString *try = [arrayTitoloEs objectAtIndex:indexPath.row];
if ([[try substringToIndex:1]isEqualToString:@"-"]) {
cell.titleEs.frame = CGRectMake(0, 0, cell.frame.size.width-15, cell.frame.size.height);
}
return cell;
}
,你可以从与细胞开始看到图片 - 最小和文本移动到左侧,在接下来的细胞好的,但最后一个单元格中的文本已移动,但不应该!
感谢所有
请勿同时创建两个单元格,然后选择返回其中一个单元格。只根据条件创建并返回一个。 – rmaddy
感谢您的回答,此代码已解决我的问题 – Ilario
欢迎您:) – Beppe