Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.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 01-01-2010, 05:22 PM   #1 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default Linking to a position in a scrolling view

Hi all,

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.

Fest.
fest is offline   Reply With Quote
Old 01-01-2010, 05:38 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

A little fuzzy which question you're asking.

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.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 05:40 PM   #3 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
A little fuzzy which question you're asking.

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.
fest is offline   Reply With Quote
Old 01-01-2010, 05:44 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 05:47 PM   #5 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
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.

Fest
fest is offline   Reply With Quote
Old 01-01-2010, 06:16 PM   #6 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by fest View Post
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:

Code:
[scrollView setContentOffset:CGPointMake(480,0) animated:NO];
now all I need is to pass a value: 480, 960, 1440, 2000 etc for pages 1-4 from the index view.
fest is offline   Reply With Quote
Old 01-01-2010, 06:19 PM   #7 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

First view controller:
Button tags = 1, 2, 3, 4...

Scroll view controller:
xOffset = (currentTag - 1) * 480;
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 06:24 PM   #8 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
First view controller:
Button tags = 1, 2, 3, 4...

Scroll view controller:
xOffset = (currentTag - 1) * 480;
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.
fest is offline   Reply With Quote
Old 01-01-2010, 06:29 PM   #9 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

If the buttons are in IB, tag is one of the fields in the inspector. Select a button and hit cmd-1. If not, setTag:

Your action should look something like this:
Code:
- (IBAction)buttonPressed:(id)sender;
To retrieve the tag:
Code:
int theTag = [sender tag];
Make a property in your scroll view controller, possibly called currentIndex.

Code:
ScrollViewController *svc = ....
[svc setCurrentIndex: [sender tag]];
In your scroll view controller:
Code:
[... setContentOffset:...(([self currentIndex] - 1) * 480, 0)];
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 06:33 PM   #10 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
If the buttons are in IB, tag is one of the fields in the inspector. Select a button and hit cmd-1. If not, setTag:

Your action should look something like this:
Code:
- (IBAction)buttonPressed:(id)sender;
To retrieve the tag:
Code:
int theTag = [sender tag];
Make a property in your scroll view controller, possibly called currentIndex.

Code:
ScrollViewController *svc = ....
[svc setCurrentIndex: [sender tag]];
In your scroll view controller:
Code:
[... setContentOffset:...(([self currentIndex] - 1) * 480, 0)];
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?
fest is offline   Reply With Quote
Old 01-01-2010, 06:35 PM   #11 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Not automatically, you have to provide it. That's what this part is doing:

Code:
[svc setCurrentIndex: [sender tag]];
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 06:55 PM   #12 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
Not automatically, you have to provide it. That's what this part is doing:

Code:
[svc setCurrentIndex: [sender tag]];
Ok I am not very far into this and I am stuck, this is how I was opening the view:

Code:
- (IBAction)pageOne {	

	page1 *page1Controller = [[page1 alloc] initWithNibName:@"page1" bundle:nil];
	;
	
	page1Controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
	[self presentModalViewController:page1Controller animated:YES];
	
	[page1Controller release];
}
When I change it to pageOneid)sender; {

The code still compiles but then when I press the button, the application closes.

Also, when I try and retrieve the tag by using:

int theTag = [sender tag]; I get a compile error: 'sender' undeclared here
fest is offline   Reply With Quote
Old 01-01-2010, 06:59 PM   #13 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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).
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 07:23 PM   #14 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
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.
fest is offline   Reply With Quote
Old 01-01-2010, 07:27 PM   #15 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

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];
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Old 01-01-2010, 07:52 PM   #16 (permalink)
Registered Member
 
fest's Avatar
 
Join Date: Dec 2009
Location: Ammanford, UK
Posts: 92
Default

Quote:
Originally Posted by BrianSlick View Post
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.
fest is offline   Reply With Quote
Old 01-01-2010, 07:55 PM   #17 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

You need a property in your scroll view controller. You will pass in the necessary information via that property when you create the view controller.

Although mostly geared towards memory management which isn't the current issue, see the properties link in my signature for more information.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

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

Are you a newbie? Things you should read:
BrianSlick is online now   Reply With Quote
Reply

Bookmarks

Tags
uiimageview, uiscrollview

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: 269
20 members and 249 guests
ADY, AragornSG, BrianSlick, Dani77, Dattee, dre, glenn_sayers, HDshot, HemiMG, JasonR, karlam963, nobre84, prchn4christ, Rudy, spiderguy84, themathminister, tomtom100, viniciusdamone, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

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