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 Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-02-2010, 12:33 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 27
tjnew is on a distinguished road
Default Change Cell Image when didselect.

Hello,
I m trying to find how i could change cell's image with didselect method.

here is my code.

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

static NSString *MyIdentifier = @"Cell";

cell =((MainCellnew *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier]);
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"MainCellnew" owner:self options:nil];
}


[cell changeimage:[UIImage imageNamed:@"image_1.png"] ];

return cell;

}

all my cells now have image_1.png and everything is ok.

- (void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath {

HERE I WANT TO CHANGE THE IMAGE OF SELECTED IndeXPath.row
[cell changeimage:[UIImage imageNamed:@"image_2.png"]];

next *controller = [[next alloc] initWithNibName:@"next" bundle:nil];

[self.navigationController pushViewController:controller animated:YES];

}

Than you for any help.
tjnew is offline   Reply With Quote
Old 02-03-2010, 04:26 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Did you try calling cellForRowAtIndexPath? Hopefully that will give you the existing cell if it's not on the screen, and not create a new one. I did not test this, however.

Code:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-04-2010, 03:15 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 27
tjnew is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
Did you try calling cellForRowAtIndexPath? Hopefully that will give you the existing cell if it's not on the screen, and not create a new one. I did not test this, however.

Code:
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
Thank you for your help

it works temporary because when i scroll my tableview the first image return back.

is there anything else i can do?

i would like to keep the second image till the next time that my table view reload data.
tjnew is offline   Reply With Quote
Old 02-04-2010, 03:19 PM   #4 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

Quote:
Originally Posted by tjnew View Post
Thank you for your help

it works temporary because when i scroll my tableview the first image return back.

is there anything else i can do?

i would like to keep the second image till the next time that my table view reload data.
Then you need to store that data somewhere so that cellForRowAtIndexPath can load the correct image. your cellForRowAtIndexPath always loads image_1.png, right? you need to keep track of which cell is selected so that you can load the right image.
__________________

Free Games!
smasher is offline   Reply With Quote
Old 02-15-2010, 11:33 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 27
tjnew is on a distinguished road
Default

Quote:
Originally Posted by smasher View Post
Then you need to store that data somewhere so that cellForRowAtIndexPath can load the correct image. your cellForRowAtIndexPath always loads image_1.png, right? you need to keep track of which cell is selected so that you can load the right image.
yes my cellForRowAtIndexPath loads always image_1.png.
Could your provide me plz with an example what you mean because i still have the problem.

thanks
tjnew is offline   Reply With Quote
Old 02-15-2010, 02:22 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 27
tjnew is on a distinguished road
Default

Quote:
Originally Posted by tjnew View Post
yes my cellForRowAtIndexPath loads always image_1.png.
Could your provide me plz with an example what you mean because i still have the problem.

thanks
The problem finally solved keeping value (yes,no) for every cell in new nsmutablearray. so everytime i select new cell the value change to yes. and the with if statement i was able to appear the correct image.

thanks
tjnew is offline   Reply With Quote
Old 02-15-2010, 02:24 PM   #7 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

So cellForRowAtIndexPath always loads image 1.
Then you select the cell, and a new image is loaded.
Then you scroll off the screen, and the cell is destroyed (or recycled).
Then you scroll it back onto the screen and a new cell is created with cellForRowAtIndexPath which always loads image 1.

That last step is the broken one - you need to check if the cell being created is for the selected item, and load the right image.
__________________

Free Games!
smasher 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: 400
7 members and 393 guests
13dario13, ChrisYates, fredidf, iOS.Lover, Leslie80, Wikiboo, Yosh_K
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,670
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Yosh_K
Powered by vBadvanced CMPS v3.1.0

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