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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-27-2010, 08:31 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
Default UITextView in UITableViewCell not displaying

I am trying to put a UITextView into a UITableViewCell because a UILabel won't hold the text the way I want it to. My code, below, is crashing the app 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 02-28-2010, 06:11 AM   #2 (permalink)
Dr. Touch Cocoa Helpdesk
iPhone Dev SDK Supporter
 
Join Date: Sep 2008
Location: Vienna, Austria
Posts: 537
Send a message via AIM to Oliver Drobnik Send a message via MSN to Oliver Drobnik Send a message via Skype™ to Oliver Drobnik
Default

Quote:
Originally Posted by starwarsdevwookie59 View Post
I am trying to put a UITextView into a UITableViewCell because a UILabel won't hold the text the way I want it to. My code, below, is crashing the app 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
This code for the cell itself is fine. You need to check the console to see that the real crashing reason is. Also add a breakpoint at OBJ_EXCEPTION_THROW to see where the exception occurs. I suspect that your stories array does not look like you assume in your code.
__________________
regards

Oliver Drobnik
Cocoanetics - Our DNA is programmed in Objective-C.

Linguan – makes localizing strings file fun!

Cocoanetics Parts Store – easy to use yet professionally looking components that you can use to spruce up your own apps. Augmented Reality, Calendar Control, Pin Lock or Purchase Button are only some examples. You get full source code, no static library crap, and lifetime support. Check it out today!
Oliver Drobnik is offline   Reply With Quote
Old 02-28-2010, 01:38 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2009
Posts: 157
Default

Quote:
Originally Posted by Oliver Drobnik View Post
This code for the cell itself is fine. You need to check the console to see that the real crashing reason is. Also add a breakpoint at OBJ_EXCEPTION_THROW to see where the exception occurs. I suspect that your stories array does not look like you assume in your code.
thanks so much for your reply. I should've included... my console error is
Code:
2010-02-28 12:37:43.253 bool _WebTryThreadLock(bool), 0x3ecf180: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
also, it seems like that error has something to do with the array... here's some other code in the cellForRowAtIndexPath method
Code:
static NSString *MyIdentifier = @"MyIdentifier";
	int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
	UILabel *mainLabel;

	UITextView *secondLabel;
__________________
Check out our Apps!
Boxen4Oxen
VisCenter

Film Budget

Everwell TV

Last edited by starwarsdevwookie59; 02-28-2010 at 02:00 PM.
starwarsdevwookie59 is offline   Reply With Quote
Old 02-28-2010, 03:08 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 273
Default

Quote:
Originally Posted by starwarsdevwookie59 View Post
thanks so much for your reply. I should've included... my console error is
Code:
2010-02-28 12:37:43.253 bool _WebTryThreadLock(bool), 0x3ecf180: Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now...
that error has nothing to do with initialization of a table cell, (unless i'm way off). from the looks of this, you have something going in another thread that is the problem, and is manifesting itself around the time of your cell initialization.

but short of that, i would start carefully checking the contents of your array. i'm willing to bet as well that it doesn't hold what you think it does.
mickm is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, textview, uitable, uitableviewcell, uitextview

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: 252
21 members and 231 guests
@sandris, ADY, bookesp, ckgni, dacapo, Dani77, DarkAn, Davey555, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, LEARN2MAKE, prchn4christ, Rudy, ryantcb, Speed, themathminister, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,766
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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