【发布时间】:2013-09-26 23:19:59
【问题描述】:
我对带有自定义 UITableViewCell 的 UITableView 有疑问。 该表由 NSArray 填充,如果此 NSArray 中的对象以 - 开头,我希望它改变它的外观。
问题在于以 - 开头的 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;
}
从图中可以看出,以单元格开头的单元格-最小,文本向左移动,在下一个单元格中是可以的,但是最后一个单元格中的文本被移动了,但不应该!
谢谢大家
【问题讨论】:
标签: iphone ios objective-c uitableview