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

How to make a playlist app? How to increment up and down an array and stop at one object. Objective c. iOS

I would like to make a playlist app. In the array will be multiple "music" objects. I would like to have two Buttons. in one IBAction I would like to go the next object in the array and stop on the next object.

On the other IBAction I would like to increment down the array to go the the previous object and stop at that object.

How would I go about doing that? I can't figure it out. Please help

1 Answer

If you could provide more details specific to your application (relevant source code) I can help you out a lot better. I hope this is not too general.

So you will have two IBActions, (now i'm not sure how smooth this will be when you run it), what you can do under each IBAction is just change the data sent to the views.

So let's say you have your 'music array' and you fetch the playlist data from with variable 'index'. You can just + or - the index on each IBAction. Then use the same code as you did in 'viewDidLoad' to change the relevant views.

Another way I thought of (I was trying to be a bit creative here) was create two UIWindows that switch between each other, that are not identical copies. When you execute an IBAction, you 'prepare for segue' and pass in the incremented index once again.