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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 01-25-2009, 09:13 AM   #12 (permalink)
razorzerox
Registered Member
 
Join Date: Jan 2009
Posts: 48
Default

hello everyone

I was just trying out the code above and the resizing of my cells worked great. But I am still having troubles resizing my labels so that I can see all lines and not only the first one.

My cell should look like this:

germantext1, englishtranslation1
altgermantext, englishtranslation2
altgermantext2

Here is what I have implemented so far:
Code:
-(UITableViewCell *)tableView:(UITableView *)tableView
		cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	static NSString *CellTableIdentifier = @"CellTableIdentifier";
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
	CGFloat tableViewWidth;
		CGFloat width = 0;
	CGRect bounds = [UIScreen mainScreen].bounds;
	NSString *text1, *text2 = nil;
	
	if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation))
		tableViewWidth = bounds.size.width/2;
	else
		tableViewWidth = bounds.size.height/2;
	
	width = tableViewWidth - 90; //fudge factor
	
	NSDictionary *rowData = [self.matches objectAtIndex:indexPath.row];
	text1 = [rowData objectForKey:@"german"];
	text2 = [rowData objectForKey:@"english"];
	
	if (cell == nil) {
		
		
		CGSize textSize = {width, 20000.0f}; //width and height of text area
		
		//german height
		CGSize size1 = [text1 sizeWithFont:[UIFont systemFontOfSize:12.0f]
						 constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];
		//english height
		CGSize size2 = [text2 sizeWithFont:[UIFont systemFontOfSize:12.0f]
						 constrainedToSize:textSize lineBreakMode:UILineBreakModeWordWrap];

		CGRect cellFrame = CGRectMake(0,0,300,65);
		cell = [[[UITableViewCell alloc] initWithFrame:cellFrame
									   reuseIdentifier:CellTableIdentifier] autorelease];
		//CGRectmake(x,y,width,height)
		//Setting up the english and german labels manually
		CGRect germanRect = CGRectMake(0,10,140,size1.height);
		UILabel *germanLabel = [[UILabel alloc] initWithFrame:germanRect];
		// germanLabel.textAlignment = UITextAlignmentRight;
		germanLabel.tag =kGermanTag;
		[cell.contentView addSubview:germanLabel];
		[germanLabel release];

		CGRect englishRect = CGRectMake(150,10,140,size2.height);
		UILabel *englishLabel = [[UILabel alloc] initWithFrame:englishRect];
		// englishLabel.textAlignment = UITextAlignmentRight;
		englishLabel.tag =kEnglishTag;
		[cell.contentView addSubview:englishLabel];
		[englishLabel release];
	}
	
	// Setting the costum labels to the right data
	UILabel *germanLabel = (UILabel *)[cell.contentView viewWithTag:kGermanTag];
	germanLabel.text = [rowData objectForKey:@"german"];
	
	UILabel *englishLabel = (UILabel *)[cell.contentView viewWithTag:kEnglishTag];
	englishLabel.text = [rowData objectForKey:@"english"]; 
	
	return cell;
}
The text Sizes of my labels seem to be ok..but I still dont see any changes in the numbers of lines I can actually see. I tried working with layoutSubviews and SizeToFit..both with no success.

Help would be greatly appreciated
Andre

Last edited by razorzerox; 01-25-2009 at 06:35 PM.
razorzerox is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 158,850
Threads: 89,215
Posts: 380,665
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jaraspl
Powered by vBadvanced CMPS v3.1.0

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