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

View Single Post
Old 03-05-2010, 06:35 PM   #2 (permalink)
Louis002
Registered Member
 
Join Date: Feb 2010
Posts: 3
Louis002 is on a distinguished road
Default Here is a good template that i use for tableviews

Code:
// replace your cellForRowAtIndexPath with this one
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
	
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
	}
	cell = [self getCellContentView:CellIdentifier:indexPath.row];    
	
    return cell;
}

// add this function to your code
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier:(int)cellIndex {
	
// make sure your height below matches your cell height set
// or your cells will not be lined up with the color
	CGRect CellFrame = CGRectMake(0, 0, 320, 60);
	UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease];
	
	// put a UIView underneath for coloring
	UIView * view = [[UIView alloc] initWithFrame:CellFrame];
	
	if ( cellIndex%2 == 0 ){
// edit your cell color below
		view.backgroundColor = [UIColor whiteColor];
	}else{
// edit cell color 2 below
		view.backgroundColor = [UIColor colorWithRed:.238 green:.238 blue:0.238 alpha:.10];
	}
	[cell.contentView addSubview:view];
	[view release];
	
		
	return cell;
}


///// this template will allow you to color every other cell a different color if desired replace your cellForRowAtIndexPath ... and add the cellIdentifier function
Louis002 is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,535
Threads: 94,052
Posts: 402,640
Top Poster: BrianSlick (7,979)
Welcome to our newest member, Chayolei001
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.