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 11-21-2010, 11:54 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default Table View Cell Customization

Hello,

I am new to the iPhone SDK and would like to know some stuff on table view cells. I have created a navigation based applications using XCODE and have set up a table view that has writing and allows you to navigate to other views.

However, I would like to know how I can add different images to each of these table view cells. Each table view cell should have an image on the left side and then my text on the right. If you guys can do this, it would be really helpful. Thanks in advance...
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 12:43 AM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Check out the class reference for UITableViewCell here Loading…

You can use the imageView property of each cell and set it ([[cell imageView] setImage:anImage]) when you load the cells in the tableView:cellForRowAtIndexPath: method of your UITableViewDelegate.
baja_yu is offline   Reply With Quote
Old 11-22-2010, 05:34 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Check out the class reference for UITableViewCell here Loading…

You can use the imageView property of each cell and set it ([[cell imageView] setImage:anImage]) when you load the cells in the tableView:cellForRowAtIndexPath: method of your UITableViewDelegate.
I have multiple cells. Can you tell me how to put a separate image for each cell?? Thanks...
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 05:41 PM   #4 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Code:
if ([[cell textLabel].text isEqualToString:@"name"])
{
[cell imageView] setImage:[UIImage imageNamed:@"image name"];
}
Quote:
Originally Posted by mehtaapplications View Post
I have multiple cells. Can you tell me how to put a separate image for each cell?? Thanks...
iSDK is offline   Reply With Quote
Old 11-22-2010, 05:53 PM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Code:
if ([[cell textLabel].text isEqualToString:@"name"])
{
[cell imageView] setImage:[UIImage imageNamed:@"image name"];
}
I tried that under CellForRowatIndexPath and when I load my table view there was no images. I have not done anything in interface builder. I have an array that stores the context of my table view cell. Thankksss..

// Configure the cell.

if ([[cell textLabel].text isEqualToString:@"Weapons"])
{
[cell imageView];
setImage:[UIImage imageNamed:@"box2.png"];
}

Last edited by mehtaapplications; 11-22-2010 at 05:55 PM.
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 05:54 PM   #6 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

I missed out a bracket

Code:
if ([[cell textLabel].text isEqualToString:@"name"])
{
[[cell imageView] setImage:[UIImage imageNamed:@"image name"]];
}
Quote:
Originally Posted by mehtaapplications View Post
I tried that under cellForRowAtIndexPath and after //configure the cell and got an error saying "Expected a ; before setImage...Why?
iSDK is offline   Reply With Quote
Old 11-22-2010, 05:58 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
I missed out a bracket

Code:
if ([[cell textLabel].text isEqualToString:@"name"])
{
[[cell imageView] setImage:[UIImage imageNamed:@"image name"]];
}
// Configure the cell.

if ([[cell textLabel].text isEqualToString:@"Weapons"])
{
[[cell imageView] setImage:[UIImage imageNamed:@"box2.png"]];
}

still nothing...
I did nothing in interface builder tho...
Thanks
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 06:02 PM   #8 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Thats wierd. Try this I have simplified it a bit more:



Code:
if (cell.textLabel.text == @"Weapons")
	{
		cell.imageView.image = [UIImage imageNamed:@"box2.png"];
	}
Quote:
Originally Posted by mehtaapplications View Post
// Configure the cell.

if ([[cell textLabel].text isEqualToString:@"Weapons"])
{
[[cell imageView] setImage:[UIImage imageNamed:@"box2.png"]];
}

still nothing...
I did nothing in interface builder tho...
Thanks
iSDK is offline   Reply With Quote
Old 11-22-2010, 06:10 PM   #9 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Thats wierd. Try this I have simplified it a bit more:



Code:
if (cell.textLabel.text == @"Weapons")
	{
		cell.imageView.image = [UIImage imageNamed:@"box2.png"];
	}
I used an array on the table view called rootGuide. Here is my method:

// Customize the appearance of table view cells.
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell.

if (cell.textLabel.text == @"Weapons")
{
cell.imageView.image = [UIImage imageNamed:@"#1.jpg"];
}



cell.textLabel.textColor = [UIColor whiteColor];

cell.textLabel.text = [rootGuide objectAtIndex:indexPath.row];

return cell;
}



/*
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 06:27 PM   #10 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
Thats wierd. Try this I have simplified it a bit more:



Code:
if (cell.textLabel.text == @"Weapons")
	{
		cell.imageView.image = [UIImage imageNamed:@"box2.png"];
	}
Now, it comes on all of the cells. My image does. How do I make it appear on one cell???
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 06:32 PM   #11 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Your setting the cells text label's text after.

Code:
- (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

// Configure the cell.



cell.textLabel.textColor = [UIColor whiteColor];

cell.textLabel.text = [rootGuide objectAtIndex:indexPath.row];

if (cell.textLabel.text == @"Weapons")
{
cell.imageView.image = [UIImage imageNamed:@"#1.jpg"];
}
return cell;
}
iSDK is offline   Reply With Quote
Old 11-22-2010, 06:38 PM   #12 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by mehtaapplications View Post
Now, it comes on all of the cells. My image does. How do I make it appear on one cell???

Lol never mind. I was silly. It came!!! THANKS A LOT. BTW UR WEBSITE LINK DOES NOT WORK
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 06:42 PM   #13 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

haha I know im trying to fix it up at the moment. DONT USE 000WEBHOST!!!
Quote:
Originally Posted by mehtaapplications View Post
Lol never mind. I was silly. It came!!! THANKS A LOT. BTW UR WEBSITE LINK DOES NOT WORK
iSDK is offline   Reply With Quote
Old 11-22-2010, 06:56 PM   #14 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 47
mehtaapplications is on a distinguished road
Default

Quote:
Originally Posted by iSDK View Post
haha I know im trying to fix it up at the moment. DONT USE 000WEBHOST!!!

Yeah. BTW how do I make my image be a certain number of pixels in xcode. Or fit in a certain space?
mehtaapplications is offline   Reply With Quote
Old 11-22-2010, 07:52 PM   #15 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Ok you need to do this instead:

Code:
If (cell.textLabel.text == @"Weapons")
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame: CGRectMake(0,0,0,0)]; /// set the size here;
imageView.image = [UIImage imageNamed:@"image name"];
cell.imageView = imageView;
}
Quote:
Originally Posted by mehtaapplications View Post
Yeah. BTW how do I make my image be a certain number of pixels in xcode. Or fit in a certain space?
iSDK is offline   Reply With Quote
Reply

Bookmarks

Tags
cell, customization, image, table, view

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: 375
7 members and 368 guests
apatsufas, Kirkout, lzwasyc, MarkC, Sami Gh, SamorodovAlex, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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