I have a scrolling view with 8 full sized images kind of like a photo gallery, all the images are directly dropped onto the UIScrollView as UIImageView objects within interface builder. They scroll from left to right and page correctly and each image snaps to the confines of the display area
.
I want to create an index page on a separate view, when I click the 4th image on the index, I want the scrollview to open on the 4th image in the series.
I know the best way would be to load the images into an array and call that image directly, but underneath the images are going to be hidden buttons, for example, a picture of a cow would make a cow noise when pressed.
I can't think of a simple way to do this for the life of me, any ideas are greatly appreciated.
If you're asking how to pre-scroll the view, that's setContentOffset:.
If you're asking how to keep track of everything, make a custom object that has your relevant properties, then put those objects into an array.
Well the index is first view, and each page of the index has 4 smaller buttons.
Page 1 Page 2
Page 3 Page 4
When I click Page 4, I want it to load the view which contains the UIScrollView and skip to page 4 of the scroll... It's hard to explain I guess, I know what I want it to do, but putting it into words for you guys to understand is where I fail.
Put tags on the buttons. In your IBAction, figure out which button was hit based on the tag. Load the new view. Pass in the identifier of the button, and/or pass in the custom object. In viewWillAppear in the new view, read the identifier, scroll the view accordingly.
Put tags on the buttons. In your IBAction, figure out which button was hit based on the tag. Load the new view. Pass in the identifier of the button, and/or pass in the custom object. In viewWillAppear in the new view, read the identifier, scroll the view accordingly.
That sounds perfect, now....comes the bit where I have to work out how to do everything you said, at least it's broken down for me now, and I have a process to proceed with. thanks very much for your help.
That sounds perfect, now....comes the bit where I have to work out how to do everything you said, at least it's broken down for me now, and I have a process to proceed with. thanks very much for your help.
Fest
Just an update, I managed to run the app and make it skip directly to page 2 using this line:
I guess setting the tag to a button is creating a variable (integer) and then not releasing it after opening the scrollview. kind of like setting a value when I did the helloworld app......many months ago.
I was thinking, declare a variable in the header if the index page, then when the button is pressed, in the IBAction, set the value of the integer to (page - 1) then in the same IBAction open the next view. As part of the viewdidload, the offset is then set to the pageno variable * 480. I have managed to get this working within the scrollview itself (setting a variable and then multiplying an integer etc.) will the value of the int pass from one view to the new one?
There is a difference between pageOne: and pageOne. The first one accepts an input parameter, the second doesn't.
So, you are correct to change it to pageOne:, because you do need the parameter. However, what you also must do is change what the button is pointing to. It it still pointing to pageOne, which no longer exists. That's most likely your crash.
The reason for your second message is that sender IS the parameter. So if you are still using pageOne, sender is never declared, so you can't use it (nothing exists to use).
There is a difference between pageOne: and pageOne. The first one accepts an input parameter, the second doesn't.
So, you are correct to change it to pageOne:, because you do need the parameter. However, what you also must do is change what the button is pointing to. It it still pointing to pageOne, which no longer exists. That's most likely your crash.
The reason for your second message is that sender IS the parameter. So if you are still using pageOne, sender is never declared, so you can't use it (nothing exists to use).
Ok I figured out the first problem, I was putting the (id)sender in the .m file where I was telling the button what to do, and now I have put it in the .h and it compiles and the button is working again.
Which file to I put the
Code:
int theTag = [sender tag];
because I can put it in the index.m, but still when I try and use it in page1.m it's reporting that it is undeclared. page1.m is the scrolling page.
sender is the button that triggered the method. So that variable only exists within that particular scope.
You don't necessarily need this:
Code:
int theTag = [sender tag];
You can do this:
Code:
[svc setCurrentIndex: [sender tag]];
If you do the first one, then the second one can change to:
Code:
[svc setCurrentIndex: theTag];
Well I am still getting lost here (it doesn't take a lot) I am managing to get a value for the tag field within index, but as soon as I load page1 it is undeclared. I think my main problem here is that I don't understand object-c enough to know what exactly you are trying to tell me.
I understand getting a value from the button,
I understand that in page1 (the scrolling view) that I can use the value to move move along the scroll window.
I think my problem is that each of these views are separate xib files, maybe I need to try and do this in one nib and one piece of code. I will try and do some research on passing stored integers between views in different views and code blocks. It took me six hours to get a working pausing scrollview, so I am not expecting miracles and again, your help has been invaluable in helping to understand the process, I just need to see some sample code in a tutorial, and then try and transfer that to my project.