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 09-08-2011, 02:02 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 2
Brettyboi is on a distinguished road
Default cell image in a tableView that corresponds with the cell content!

Hi everyone, I'm quite new to App development and am hoping to get some help regarding the thread title!

I've followed a tutorial which fetches data from my blog and inserts it into a tableview, each cell can then be pressed which links to the entire blog article via a webview!

I want each cell to have an image, but I want a particular image to be displayed depending on what the text in the cell is. For example, if the first word of the cell was 'News', I want an image to be displayed that is referenced as news.png.

Currently I'm using a simple if statement...

if (indexPath.row == 0)
{
cell.image = [UIImage imageNamed:@"image1.png"];
}

else if (indexPath.row == 1)
{
cell.image = [UIImage imageNamed:@"image2.png"];
}

But obviously this sets the image to a row and will never change, however I want a particular image to show up depending on what the content of the cell text is!

When the list is refreshed, and the cell text containing 'News' moves to a new index, I want the image to follow it because it contains that particular word. Any ideas guys?

If you need me to explain it clearer please say, I am still a beginner. Many thanks to anyone who can give me some guidance here!

Regards, Brett
Brettyboi is offline   Reply With Quote
Old 09-08-2011, 03:06 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 241
MattW is on a distinguished road
Default

Take the first word of your text and create a filename like so:

Code:
NSString *fileName = [NSString stringWithFormat:@"%@.png", <whatever string variable contains the first word of your text>];
And use that filename to decide which image to use.
__________________

Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)
-----
Create iPhone lists with no typing: Insta-List
-----
Make spelling fun, and create your own tests: iWillSpell
-----
A fast, elegant flashlight app: Insta-Light
-----


FourSixteen Productions
MattW is offline   Reply With Quote
Old 09-08-2011, 05:25 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 2
Brettyboi is on a distinguished road
Default

Hi Matt, thanks for your response!

Sorry to be a pain but would you mind trying to give me an example? I'm having trouble implementing the line of code provided.

Let's say that for any cell containing the word 'News' I want it to automatically display news.png, and for any cell that contains the word 'update' I want the cell to display update.png

Is the line of code you provided all I need? Or do I need to declare anything else in my header file?

Thanks again

Brett
Brettyboi is offline   Reply With Quote
Old 09-08-2011, 05:34 PM   #4 (permalink)
Registered Member
 
Join Date: Jul 2011
Posts: 241
MattW is on a distinguished road
Default

Quote:
Originally Posted by Brettyboi View Post
Hi Matt, thanks for your response!

Sorry to be a pain but would you mind trying to give me an example? I'm having trouble implementing the line of code provided.

Let's say that for any cell containing the word 'News' I want it to automatically display news.png, and for any cell that contains the word 'update' I want the cell to display update.png

Is the line of code you provided all I need? Or do I need to declare anything else in my header file?

Thanks again

Brett
You've just changed the parameters of what you're after - firstly you said that the image should be based on the "first word" of the text. Now you're implying that the cell just has to contain the word 'news' anywhere in it? What if the cell contains multiple keywords, such as "...this is an update to the news about..."?

But let's assume you're after the first word in the cell. You have the text to display in the cell, correct? So just grab the first word from that and use it as the basis for your image filename (using the code provided).

(Extract your first word of the text into an NSString variable, and replace <whatever string variable contains the first word of your text> with the name of that variable.)
__________________

Highlight PDF text like no other app: iHighlight (now available for iPad and iPhone!)
-----
Create iPhone lists with no typing: Insta-List
-----
Make spelling fun, and create your own tests: iWillSpell
-----
A fast, elegant flashlight app: Insta-Light
-----


FourSixteen Productions
MattW is offline   Reply With Quote
Reply

Bookmarks

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: 382
9 members and 373 guests
apatsufas, JackReidy, jeroenkeij, Sami Gh, tim0504, UMAD, yomo710, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,904
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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