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 03-22-2011, 08:00 AM   #1 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Question Change custom cell on tap

Hello everyone!
I Want to change my custom cell when the user tab on a cell in my table view.
I think i have to use the event didSelectRowAtIndexPath and change here, but i donīt know.. please help me!

tks!
gbergamo is offline   Reply With Quote
Old 03-22-2011, 08:06 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

What kind of change? Be specific.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-22-2011, 08:31 AM   #3 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
What kind of change? Be specific.
Sorry donīt be specific...
I want to change to another custom cell... I want to take off the current custom cell e change to other.
gbergamo is offline   Reply With Quote
Old 03-22-2011, 08:36 AM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Well, basically you will need to delete the current row, and insert a new row in the same place. You can trigger that from didSelectRow.

But, what's going to happen is the cellForRow will be called again, so that method will need to know to give you a different cell. So you are going to have to set a flag somewhere that defines which cell should be returned in that case.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-22-2011, 08:44 AM   #5 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
Well, basically you will need to delete the current row, and insert a new row in the same place. You can trigger that from didSelectRow.

But, what's going to happen is the cellForRow will be called again, so that method will need to know to give you a different cell. So you are going to have to set a flag somewhere that defines which cell should be returned in that case.
Thanks for the answer Brian...
But I'm a begginer.. did you see the new twitter app? they have a customcell, when you slide the finger on a cell, another cell appear and you have some options. When you slide your finger on another cell, that fisrt cell changed returns and the options appear on the current cell.

This have to be hard to do, but I have to do...

Thanks a lot!
gbergamo is offline   Reply With Quote
Old 03-22-2011, 08:45 AM   #6 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

The process I described is most likely what they are doing.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-22-2011, 08:45 PM   #7 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
The process I described is most likely what they are doing.
Man, I found how can I delete the current row, but I don't find how can I insert the new custom Cell, I'll trying something like this:

Code:
[tableView deselectRowAtIndexPath:indexPath animated:UITableViewRowAnimationFade];
    
    [[vagasArray retain] autorelease];
    [vagasArray removeObjectAtIndex:indexPath.row];
    
    [tableView beginUpdates];
    
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    
    [tableView endUpdates];
I don't have any ideas how can i do this..

tks
gbergamo is offline   Reply With Quote
Old 03-22-2011, 08:46 PM   #8 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

There is also an insertRowsAtIndexPaths.

Edit:

This part doesn't make any sense:
Code:
[[vagasArray retain] autorelease];
[vagasArray removeObjectAtIndex:indexPath.row];
There is no reason to retain/release the array.
And you don't want to remove anything from your array. You will still have the same number of objects.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-22-2011, 09:06 PM   #9 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
There is also an insertRowsAtIndexPaths.

Edit:

This part doesn't make any sense:
Code:
[[vagasArray retain] autorelease];
[vagasArray removeObjectAtIndex:indexPath.row];
There is no reason to retain/release the array.
And you don't want to remove anything from your array. You will still have the same number of objects.
If I don't remove the item on array I have the follow error:
"Invalid update: invalid number of rows in section 0"

How can I use the insertRowsAtIndexPath? Because I try to use that, but I only reInsert the row.

Brian thanks a lot for the answers..
gbergamo is offline   Reply With Quote
Old 03-22-2011, 09:32 PM   #10 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

You're doing 2 actions here. The cell that is sliding out is being deleted. The cell that is sliding in is being inserted. So you need to do both actions at the same time inside that update block.

And that's why the number of items in the array doesn't need to change.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-23-2011, 08:40 AM   #11 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
You're doing 2 actions here. The cell that is sliding out is being deleted. The cell that is sliding in is being inserted. So you need to do both actions at the same time inside that update block.

And that's why the number of items in the array doesn't need to change.
Ok Brian... thanks a lot!

I don't know how insert a new CustomCell, you can post a code example for me? please.
I have a CustomCell that is my customcells on the tableView, and I have a CustomDetailCell that will have to appear after a tap or slide on the cell.

thanks again!
gbergamo is offline   Reply With Quote
Old 03-23-2011, 08:43 AM   #12 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

No, I'm not going to post code. You will need to do some experimenting and figure this out.

Do this:

Code:
[tableView beginUpdates];
    
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    
[tableView endUpdates];
...and watch what happens. Add some logs to cellForRow to see when it gets called.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-23-2011, 08:50 AM   #13 (permalink)
iOS Dev
 
Join Date: Mar 2011
Location: Brazil
Age: 26
Posts: 103
gbergamo is on a distinguished road
Send a message via ICQ to gbergamo Send a message via MSN to gbergamo Send a message via Skype™ to gbergamo
Default

Quote:
Originally Posted by BrianSlick View Post
No, I'm not going to post code. You will need to do some experimenting and figure this out.

Do this:

Code:
[tableView beginUpdates];
    
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    
[tableView endUpdates];
...and watch what happens. Add some logs to cellForRow to see when it gets called.
I've tried to do this..
In this case, I delete a row and insert the sane row.
gbergamo is offline   Reply With Quote
Old 03-23-2011, 08:51 AM   #14 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

Yes, that's the first step.

Now the second step is to make cellForRow give a different cell in this case. This will require some programming logic.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Reply

Bookmarks

Tags
custom cell, didselectrowatindexpath, 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: 361
10 members and 351 guests
condor304, dansparrow, Domele, dreamdash3, ilmman, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,662
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, shagor012
Powered by vBadvanced CMPS v3.1.0

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