Hi everyone, I am working on a project that has a uitableview with 3 rows in 1 section. Now, is what I would like to do is to be able to have 1 of those 3 cells be dynamic in height. First off, I don't even know if thats possible. If it is, then I want to do it! I found a very useful tutorial helping me through it, here. I implemented the StringHelper files he recommended, and they work great for one cell, but when there are multiple cells, I begin to have issues. This picture illustrates what happens when I save the text:
And as you can see for whatever reason randomly inserts a nice little arab looking symbol at the beginning.
So, here is the code I am working with:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *label = [entree.notes/*putting entree.notes here may or may not be correct*/ length] == 0 ? kDefaultNoteLabel : aNote;
CGFloat height = [label RAD_textHeightForSystemFontOfSize:kTextViewFontSize] + 40.0;
return height;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
aNote = entree.notes;
NSString *label = [aNote length] == 0 ? kDefaultNoteLabel : aNote;
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"Name";
cell.detailTextLabel.text = entree.title;
break;
case 1:
cell.textLabel.text = @"Date";
cell.detailTextLabel.text = [self.dateFormatter stringFromDate:entree.date];
break;
case 2:
//aNote = entree.notes;
if ([[cell.contentView subviews] count] > 0) {
id view = [[cell.contentView subviews] objectAtIndex:0];
UILabel *labelToSize = view;
[label RAD_resizeLabel:labelToSize WithSystemFontOfSize:kTextViewFontSize];
} else {
UILabel *cellLabel;
cellLabel = [label RAD_newSizedCellLabelWithSystemFontOfSize:kTextViewFontSize];
[cell.contentView addSubview:cellLabel];
[cellLabel release];
}
cell.textLabel.text = @"Notes";
cell.detailTextLabel.text = entree.notes;// description];
break;
}
return cell;
}
Where entree is the name of my NSManaged Object, and title, date, notes are the attributes. All I need is to be able to set cell 3, or the notes attribute to a dynamic height so that when they input large amounts of text, that cell and only that cell moves, and everything else stays the same. As you can see, I have been trying some things, I apologize if it has gotten kind of messy, but this current setup of code, produces the images above, which is close, but not quite there. It may just be a quick fix, so if anyone out there can help me out, it would be greatly appreciated! Thanks in advance