Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Destructive Message Tutorial IOS

Hello everyone I was following the tutorial but I had a question for you ... In my app the friend request is not made through didSelectedRow but with the use of a custom button on the custom cell ... At this point, how can I maintain the state of the button active or inactive? when I scroll the tableview the button does not remain in its current state but returns to its original state ... Example: if the user clicks the button turns orange but when I scroll the tableview is not orange but gray back ... Can you help me in this ???

2 Answers

Hi Fabio,

It sounds like you need to save the friend requests once they are done, so you have an array to check when the buttons are being redrawn.

One idea is to save all the requests in an array and save the array using NSUserDefaults - Assign the buttons a tag number based on the user they would correspond to and save that number in the array. When you redraw the button in the cell, first calculate its tag number, check against the array and, if found -> orange, if not -> gray...

While this is a simple implementation, you could run into problems if the number of requests are getting higher and higher.

Hello Robert, is there any article here on treesHouse that I can see to understand ??? I have a photographic memory I can learn a lot if I really see what you're talking about ...

As for the problems you're talking about ... if I understand correctly this method might work well if I have a few friend requests right? otherwise there may be problems ... I understand you correctly?

I forgot to tell you that I use parse.com for data management

Don't know if an article similar to what you need exists, purely because it's a rather specific request. If you can share your code that displays the table cells and adds the buttons, I will be able to help you with some additional code.

As for the problems I was talking about, yes, but only once you start having thousands of pending requests. You could just go and remove the id from the array once the friendship is complete.

Example logic: Where the tag is being calculated, if they are friends already and the tag exists in the array, remove it and carry on.

Well...I'm solved... Robert you have been very kind ... thank you very much !!!