Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-10-2010, 02:47 PM   #1 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 61
Leon112 is on a distinguished road
Default need help with heightForRowAtIndexPath please

hello, ive been struggling to assign dynamic height for my cell in the table, ive tried many thing but none of them worked... from reading i gather that my best way or rather only way to do this is by using heightForRowAtIndexPath.. can some one assist me please on where and how i should be using this? below is my code.

Code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
	
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

	

    // Configure the cell.
    [self configureCell:cell atIndexPath:indexPath];
    
    return cell;
}

Code:
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    
    NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
	cell.textLabel.text = [[managedObject valueForKey:@"text"] description];
	

	cell.textLabel.numberOfLines = 0;

	cell.textLabel.font = [UIFont systemFontOfSize:16];

    
}

Last edited by Leon112; 07-10-2010 at 02:51 PM.
Leon112 is offline   Reply With Quote
Old 07-10-2010, 02:59 PM   #2 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 61
Leon112 is on a distinguished road
Default

hello , sorry for my quick reply but it always happens right after i post something here... i think i just figured it out using the below code but not sure if i am doing it right....


Code:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
	NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
	NSString *temp = [[managedObject valueForKey:@"text"] description];
	
	struct CGSize size;
	size = [temp sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300.0, 4000) lineBreakMode:UILineBreakModeCharacterWrap];
	return size.height * 1.5;	
}
Leon112 is offline   Reply With Quote
Old 07-11-2010, 09:05 AM   #3 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 61
Leon112 is on a distinguished road
Default

any ideas? help?
Leon112 is offline   Reply With Quote
Old 07-11-2010, 06:25 PM   #4 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 54
amatoria is on a distinguished road
Default

Couple of things to correct...
1. Specify the same line break mode while creating the cell...
2. Don't give font size different while creating cell and calculating height of cell.

Also, in height function, return size.height (not size.height * 1.5) unless you are sure of what you are doing here. Add some delta (20 something) to it, don't scale it.

I hope it helps.
~Ashok
amatoria is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 326
15 members and 311 guests
akphyo, alexP, cgokey, EXOPTENDAELAX, flamingliquid, guusleijsten, mariano_donati, ohmniac, Paul Slocum, PavelSea, SLIC, Sloshmonster, Sonuye857, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,653
Threads: 94,115
Posts: 402,888
Top Poster: BrianSlick (7,990)
Welcome to our newest member, ohmniac
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:32 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0