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 02-27-2010, 04:36 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default UILabel in Cell not showing up until selected

I have an RSS reader that I'm putting both the summary and title in a cell. I set up the cells just like apple taught me...
Code:
#define MAINLABEL_TAG 1
#define SECONDLABEL_TAG 2

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *MyIdentifier = @"MyIdentifier";
	int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	UILabel *mainLabel, *secondLabel;

	
	if (cell == nil) {
		cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
		cell.selectionStyle = UITableViewCellSelectionStyleGray;
		
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
		
        mainLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)] autorelease];
        mainLabel.tag = MAINLABEL_TAG;
        mainLabel.font = [UIFont systemFontOfSize:12.0];
        mainLabel.textAlignment = UITextAlignmentLeft;
        mainLabel.textColor = [UIColor darkGrayColor];
        mainLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:mainLabel];
		
        secondLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 20.0, 320.0, 25.0)] autorelease];
        secondLabel.tag = SECONDLABEL_TAG;
        secondLabel.font = [UIFont systemFontOfSize:12.0];
        secondLabel.textAlignment = UITextAlignmentLeft;
        secondLabel.textColor = [UIColor darkGrayColor];
        secondLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleHeight;
        [cell.contentView addSubview:secondLabel];
		
    } else {
        mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
        secondLabel = (UILabel *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
    }

    mainLabel.text = [[stories objectAtIndex: storyIndex]objectForKey:@"title"];
    secondLabel.text = [[stories objectAtIndex: storyIndex]objectForKey:@"summary"];
	
	return cell;
}
but when the cell loads, the text in the mainLabel doesn't appear until I select it. any ideas? Thanks in advance...
__________________
Check out our Apps!
Boxen4Oxen
VisCenter

Film Budget

Everwell TV
starwarsdevwookie59 is offline   Reply With Quote
Old 02-27-2010, 04:39 PM   #2 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 102
chrysb is on a distinguished road
Default

Sometimes one elements draws on top of another. Make sure the things you are drawing inside of the row do not have a height greater than the row itself.

Also, make sure you're not drawing the second label on top of it.

Good debugging tactic is to strip away everything but the main label, and get that to show up first, then add the other layers back in.

Hope this helps.
chrysb is offline   Reply With Quote
Old 02-27-2010, 07:29 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
starwarsdevwookie59 is on a distinguished road
Default

Thanks, it did help.

New problem though... I decided to put a UItextview in the cell instead of a UIlabel because it wouldn't hold the string. the code crashes it every time.

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	static NSString *MyIdentifier = @"MyIdentifier";
	int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	UILabel *mainLabel;
	UITextView *secondLabel;

	
	if (cell == nil) {
		
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
		cell.contentView.autoresizesSubviews = YES;
		cell.contentView.clipsToBounds = YES;
		
        mainLabel = [[UILabel alloc] initWithFrame:CGRectMake(5.0, 5.0, 310.0, 50.0)];
		[mainLabel autorelease];
        mainLabel.tag = MAINLABEL_TAG;
        mainLabel.font = [UIFont boldSystemFontOfSize:16.0];
        mainLabel.textAlignment = UITextAlignmentLeft;
        mainLabel.textColor = [UIColor blackColor];
		mainLabel.numberOfLines = 2;
        [cell.contentView addSubview:mainLabel];
		 
		
        secondLabel = [[UITextView alloc] initWithFrame:CGRectMake(5.0, 5.0, 310.0, 50.0)];
		[secondLabel autorelease];
        secondLabel.tag = SECONDLABEL_TAG;
		secondLabel.editable = NO;
		secondLabel.scrollEnabled = NO;
		secondLabel.backgroundColor =[UIColor clearColor];
        secondLabel.font = [UIFont systemFontOfSize:12.0];
        secondLabel.textAlignment = UITextAlignmentLeft;
        secondLabel.textColor = [UIColor darkGrayColor];
        [cell.contentView addSubview:secondLabel];
		 
		
    } else {
       mainLabel = (UILabel *)[cell.contentView viewWithTag:MAINLABEL_TAG];
       secondLabel = (UITextView *)[cell.contentView viewWithTag:SECONDLABEL_TAG];
    }
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	cell.selectionStyle = UITableViewCellSelectionStyleGray;
	
	mainLabel.text = [[stories objectAtIndex: storyIndex]objectForKey:@"title"];
    secondLabel.text = [[stories objectAtIndex: storyIndex]objectForKey:@"summary"];
	
	return cell;
}
any help is much appreciated.
__________________
Check out our Apps!
Boxen4Oxen
VisCenter

Film Budget

Everwell TV
starwarsdevwookie59 is offline   Reply With Quote
Old 03-01-2010, 01:30 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 102
chrysb is on a distinguished road
Default

I'm not sure why it's crashing -- if you want a UILabel to span multiple lines properly, take a look at this:

RaddOnline: iPhone SDK: Resizing a UITableViewCell to Hold Variable Amounts of Text, Part 2 of 2

Worked great for me!
chrysb is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, custom, uilabel

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: 347
9 members and 338 guests
2Apps1Day, akacaj, c2matrix, esoteric, givensur, mjnafjke, Pudding, SLIC, Techgirl-52
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,650
Threads: 94,115
Posts: 402,887
Top Poster: BrianSlick (7,990)
Welcome to our newest member, soohyun
Powered by vBadvanced CMPS v3.1.0

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