new to objective c - help with tiny problem

Joined
Jun 9, 2010
Messages
1
Reaction score
0
Points
1
having trouble finding documentation showing how to utilize an object's properties to set the text label for a cell within UITableView's cellForRowAtIndexPath method:

Code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
	if(cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
	}
	
//a temporary representation of a class object from an array	
tempObj = [[ItemEntry alloc] init];
	tempObj = [entries objectAtIndex:[indexPath row]];
				  
				  
	//this doesn't work and i'm not sure why...
	[[cell textLabel] setText:[tempObj.entryName]];

	[tempObj release];
	tempObj = nil;
	
	return cell;

	
}
Any help straightening out this total noob is appreciated!
 
Joined
Jun 25, 2005
Messages
3,231
Reaction score
112
Points
63
Location
On the road
Your Mac's Specs
2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
I would do an NSLog on the entryName like so;
Code:
NSLog(@"[tempObj.entryName] %@", [tempObj.entryName]);
This allows you see what that text contains, if anything.


I don't see a need to allocate and release tempObj either. All you care about here is the pointer, not recreating the whole object from your array. So I think the following is fine for the affect 5 lines:

Code:
id tempObj = [entries objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[tempObj.entryName]];

Note that you likely want to replace 'id' with the appropriate class name and pointer symbol '*'.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top