3
當我從我的tableview中刪除一行時,剩下的行高度get減少了大約20個點/像素/無論蘋果錶行被測量。當我第一次顯示錶行時,內容 - 我配置的內容是這樣的:UITableView刪除行縮小錶行高
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set up the cell...
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
Favorite *thisFavorite = [self.arrResults objectAtIndex:[indexPath row]];
NSMutableAttributedString* strAtttributedText;
// Define general attributes for the entire text
NSDictionary *attribs = @{
NSForegroundColorAttributeName: cell.textLabel.textColor,
NSFontAttributeName: cell.textLabel.font
};
NSString* strCellText = [NSString stringWithFormat:@"%@\n%@\n%@", thisFavorite.favName, thisFavorite.favAddress, thisFavorite.favCity];
//get location of first return TO DO - need to figure out how to return the range from the string above
NSRange newLineRange = [strCellText rangeOfString: @"\n"];
NSRange firstLineRange = NSMakeRange(0, newLineRange.location);
NSRange restOfTextRange = NSMakeRange(newLineRange.location + 1, strCellText.length-newLineRange.location-1);
strAtttributedText = [[NSMutableAttributedString alloc] initWithString:strCellText attributes:attribs];
[strAtttributedText setAttributes:@{NSForegroundColorAttributeName:MPL_BLUE} range:firstLineRange];
[strAtttributedText setAttributes:@{NSForegroundColorAttributeName:MPL_LIGHTGRAY, NSFontAttributeName:TABLE_CELL_FONT} range:restOfTextRange];
cell.textLabel.attributedText = strAtttributedText;
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
}
,我刪除的行是這樣的:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
Favorite* thisFavorite = [self.arrResults objectAtIndex:indexPath.row];
[self.tableView beginUpdates];
NSArray* arrIndexPaths = [NSArray arrayWithObjects:indexPath, nil];
[self.tableView deleteRowsAtIndexPaths:arrIndexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.arrResults removeObjectAtIndex:indexPath.row];
[self.tableView endUpdates];
[self.myController deleteManagedObject:thisFavorite];
}
}
在那裏我會管理這個過程中,細胞的高度?
我可以得到初始細胞幀(它們都是相同的內容風格 - 名\ n地址\ ncity,州,郵編)從這裏:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
self.cellSize = cell.frame;
}
我試圖下探self.tableview.rowHeight =自.cellSize.size.height介於開始和結束編輯之間,但沒有任何影響。
任何幫助,將不勝感激。
這做到了。但是我仍然想知道如何在tableview第一次出現時看到單元格全部適應內容的高度,但是一旦編輯了一行,單元格的大小就會減小? – PruitIgoe
我認爲這個答案可能會解釋這一點:http://stackoverflow.com/a/25511053/211040 –