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 01-23-2011, 08:34 AM   #1 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 4
carlosbutler is on a distinguished road
Question UITableViewCell Rotation

Hi there! New to the forum - I hope to contribute when I find something that I can answer

I do have a question though:
I am trying to redraw my custom table cells when the device is rotated. So far I have what is below, and it sort of works. If I rotate the device, some change, and then I rotate the device again, and some more change, but it is not in any specific order and none are linked together.

So far I am only trying to push the labels further right when rotated (just to see if I can get it to work). I am doing [self.tableView reloadData]; when the device changes orientation.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	
	static NSInteger LineNameTag = 2, StatusTag = 3;
	
	UIInterfaceOrientation destinationOrientation = self.interfaceOrientation;
	
	if (destinationOrientation == UIInterfaceOrientationPortrait || destinationOrientation == UIInterfaceOrientationPortraitUpsideDown) {
		static NSString *CellIdentifier = @"Cell";
		UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
		
		if (cell == nil) {
			cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
			CGRect textFrame;
			textFrame.origin.x = 10;
			textFrame.origin.y = 5;
			textFrame.size.height = 15;
			textFrame.size.width = 200;
			
			UILabel *lineName = [[UILabel alloc] initWithFrame:textFrame];
			lineName.tag = LineNameTag;
			[cell.contentView addSubview:lineName];
			[lineName release];
			
			textFrame.origin.y += 18;
			UILabel *status = [[UILabel alloc] initWithFrame:textFrame];
			status.tag = StatusTag;
			[cell.contentView addSubview:status];
			[status release];
		}
		
		UILabel *lineName = (UILabel *) [cell.contentView viewWithTag:LineNameTag];
		UILabel *status = (UILabel *) [cell.contentView viewWithTag:StatusTag];
		
		lineName.text =[listOfLines objectAtIndex:indexPath.row];
		status.text = [statusOfLines objectAtIndex:indexPath.row];
		
		return cell;
	}
	else {
		static NSString *CellIdentifier = @"CellLandscape";
		
		UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
		if (cell == nil) {
			cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
			CGRect textFrame;
			textFrame.origin.x = 50;
			textFrame.origin.y = 5;
			textFrame.size.height = 15;
			textFrame.size.width = 200;
			
			UILabel *lineName = [[UILabel alloc] initWithFrame:textFrame];
			lineName.tag = LineNameTag;
			[cell.contentView addSubview:lineName];
			[lineName release];
			
			textFrame.origin.y += 18;
			UILabel *status = [[UILabel alloc] initWithFrame:textFrame];
			status.tag = StatusTag;
			[cell.contentView addSubview:status];
			[status release];
		}
		
		UILabel *lineName = (UILabel *) [cell.contentView viewWithTag:LineNameTag];
		UILabel *status = (UILabel *) [cell.contentView viewWithTag:StatusTag];
		
		lineName.text =[listOfLines objectAtIndex:indexPath.row];
		status.text = [statusOfLines objectAtIndex:indexPath.row];
		
		return cell;
	}
}
carlosbutler is offline   Reply With Quote
Reply

Bookmarks

Tags
custom, device, redraw, rotation, uitableviewcell

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: 361
10 members and 351 guests
7twenty7, dre, iAppDeveloper, jeroenkeij, Mah6447, Morrisone, sacha1996, Sami Gh, stanny, toon4413
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,667
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, host number one
Powered by vBadvanced CMPS v3.1.0

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