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 > iPhone SDK Development - Advanced Discussion

Reply
 
LinkBack Thread Tools Display Modes
Old 05-17-2011, 10:04 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default Issue with viewcontrollers

Hello

Here is my issue been trying to figure it out for days now!!

I have a view: crunchViewController (with .nib file and associated appdelegate file) and I have another view called slidemenu setup as follows:

@interface SlideMenu : UIView <UIScrollViewDelegate>

In the SlideMenu I have the following properties:
UIScrollView *menuScrollView;
UIImageView *rightMenuImage;
UIImageView *leftMenuImage;

with these properties:
@property (nonatomic, retain) UIScrollView* menuScrollView;
@property (nonatomic, retain) UIImageView* rightMenuImage;
@property (nonatomic, retain) UIImageView* leftMenuImage;


In my crunchviewcontroller's .m file I call the function: - (void) viewDidLoad

which creates an instance of the slidemenu as such:
slideViewControllor = [[SlideMenu alloc] initWithFrameColorAndButtons:CGRectMake(36, 210, 250, 65) backgroundColor:[UIColor clearColor] buttons:buttonArray];

which create the slidemenuview perfectly. I can scroll left and right.

I then preform the following to create a prev and next image on either side of the scrollview right after I create the scrollview:

My setup is a follows:

in the crunchViewController.h file:
UIImageView *leftScroll;
UIImageView *rightScroll;

in the crunchViewController.m file in the function: - (void) viewDidLoad

SlideMenu *slidebtns = [[SlideMenu alloc] init];
//
leftScroll = [slidebtns initLeftImagesWithFrameColor: self.view];
//
rightScroll = [slidebtns initRightImagesWithFrameColor: self.view];
//
[slidebtns release];


which calls the functions to create the image in the SlideMenu.m file as such:

-(UIImageView *)initLeftImagesWithFrameColor: (UIView *)view {
leftMenuImage = [[UIImageView alloc] initWithFrame:CGRectMake(7, 208, 25, 68)];
leftMenuImage.image = [UIImage imageNamed:@"button_prev.png"];
leftMenuImage.opaque = YES;
//
[view addSubview:leftMenuImage];
//
return leftMenuImage;
}

I call this once for the next and once for the prev images.

So right now I create the slidemenu and the two images for next and prev as displayed as well.

Now for my issue I try and controll the next and prev images from appearing and disappearing depending on the position of the slidemenu as such:

- (void)scrollViewDidScrollUIScrollView *)scrollView
{

if(scrollView.contentOffset.x <= 3)
{
leftMenuImage.hidden = YES;
//debug only
NSLog(@"Scroll is as far left as possible");
}

else if(scrollView.contentOffset.x >= (scrollView.contentSize.width - scrollView.frame.size.width)-3)
{
rightMenuImage.hidden = YES;
//debug only
NSLog(@"Scroll is as far right as possible");
}
else
{
leftMenuImage.hidden = NO;
rightMenuImage.hidden = NO;
//debug only
NSLog(@"Scroll somewhere in the middle");
}
}

which is where I am confused, because the scrollViewDidScroll function seems to be working properly since the NSLog are displaying the correct debug messages to me as the slidermenu is scrolled left and right, but the uiimages for the next and prev images are not being hidden (or unhidden) as it should.


Seems I am missing a reference somewhere or something and I just cant get it!

Can anyone help with this!!!
famictech2000 is offline   Reply With Quote
Old 05-18-2011, 07:29 AM   #2 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

please edit with code tags so we can follow your post easier
Meredi86 is offline   Reply With Quote
Old 05-18-2011, 07:49 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default

Quote:
Originally Posted by Meredi86 View Post
please edit with code tags so we can follow your post easier
I have a view: crunchViewController (with .nib file and associated appdelegate file) and I have another view called slidemenu setup as follows:

@interface SlideMenu : UIView <UIScrollViewDelegate>

In the SlideMenu I have the following properties:
Code:
UIScrollView *menuScrollView;
UIImageView *rightMenuImage;
UIImageView *leftMenuImage;

with these properties:
@property (nonatomic, retain) UIScrollView* menuScrollView;
@property (nonatomic, retain) UIImageView* rightMenuImage;
@property (nonatomic, retain) UIImageView* leftMenuImage;
In my crunchviewcontroller's .m file I call the function: - (void) viewDidLoad
which creates an instance of the slidemenu as such:
Code:
slideViewControllor = [[SlideMenu alloc] initWithFrameColorAndButtons:CGRectMake(36, 210, 250, 65) backgroundColor:[UIColor clearColor] buttons:buttonArray];
which create the slidemenuview perfectly. I can scroll left and right.

I then preform the following to create a prev and next image on either side of the scrollview right after I create the scrollview:

My setup is a follows:

in the crunchViewController.h file:
Code:
UIImageView *leftScroll;
UIImageView *rightScroll;

in the crunchViewController.m file in the function: - (void) viewDidLoad

SlideMenu *slidebtns = [[SlideMenu alloc] init];
//
leftScroll = [slidebtns initLeftImagesWithFrameColor: self.view];
// 
rightScroll = [slidebtns initRightImagesWithFrameColor: self.view];
//
[slidebtns release];
which calls the functions to create the image in the SlideMenu.m file as such:

Code:
-(UIImageView *)initLeftImagesWithFrameColor: (UIView *)view {
leftMenuImage = [[UIImageView alloc] initWithFrame:CGRectMake(7, 208, 25, 68)];
leftMenuImage.image = [UIImage imageNamed:@"button_prev.png"];
leftMenuImage.opaque = YES;
//
[view addSubview:leftMenuImage];
//
return leftMenuImage;
}
I call this once for the next and once for the prev images.

So right now I create the slidemenu and the two images for next and prev as displayed as well.

Now for my issue I try and controll the next and prev images from appearing and disappearing depending on the position of the slidemenu as such:

Code:
- (void)scrollViewDidScrollUIScrollView *)scrollView
{

if(scrollView.contentOffset.x <= 3)
{
leftMenuImage.hidden = YES; 
//debug only
NSLog(@"Scroll is as far left as possible");
}

else if(scrollView.contentOffset.x >= (scrollView.contentSize.width - scrollView.frame.size.width)-3)
{
rightMenuImage.hidden = YES;
//debug only
NSLog(@"Scroll is as far right as possible");
}
else
{
leftMenuImage.hidden = NO;
rightMenuImage.hidden = NO;
//debug only
NSLog(@"Scroll somewhere in the middle");
}
}
which is where I am confused, because the scrollViewDidScroll function seems to be working properly since the NSLog are displaying the correct debug messages to me as the slidermenu is scrolled left and right, but the uiimages for the next and prev images are not being hidden (or unhidden) as it should.
famictech2000 is offline   Reply With Quote
Old 05-18-2011, 08:14 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

So he first thing i would suggest to check is this:

Do you have in your xib file the imageVews for both left and right images or are they completely created in the program? I ask because if i want to hide something in this fashion then i have an IBOutlet for whatever element it is so in your case:
Code:
@property (nonatomic, retain) IBOutlet UIImageView* rightMenuImage;
@property (nonatomic, retain) IBOutlet UIImageView* leftMenuImage;
And then have these hooked up in interface builder.

If all three of those nslogs are showing then at least you know that you are evaluating correctly, there is just something wrong in the use of the image view
Meredi86 is offline   Reply With Quote
Old 05-18-2011, 03:02 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default

Quote:
Originally Posted by Meredi86 View Post
So he first thing i would suggest to check is this:

Do you have in your xib file the imageVews for both left and right images or are they completely created in the program? I ask because if i want to hide something in this fashion then i have an IBOutlet for whatever element it is so in your case:
Code:
@property (nonatomic, retain) IBOutlet UIImageView* rightMenuImage;
@property (nonatomic, retain) IBOutlet UIImageView* leftMenuImage;
And then have these hooked up in interface builder.

If all three of those nslogs are showing then at least you know that you are evaluating correctly, there is just something wrong in the use of the image view

This is what the scrollview has where the (which does not hace an xib file)

Code:
@interface SlideMenu : UIView <UIScrollViewDelegate> 

UIScrollView *menuScrollView;
UIImageView *rightMenuImage;
UIImageView *leftMenuImage;

with these properties:
@property (nonatomic, retain) UIScrollView* menuScrollView;
@property (nonatomic, retain) UIImageView* rightMenuImage;
@property (nonatomic, retain) UIImageView* leftMenuImage;
where I have the
Code:
@property (nonatomic, retain) UIImageView* rightMenuImage;
@property (nonatomic, retain) UIImageView* leftMenuImage;
called to create the next and prev UIImage for both.

In the crunchviewcontrol where I do have a xib file for calls the - (void) viewDidLoad function which creates the scrollview and the UIImages for the next and prev as such

Code:
SlideMenu *slidebtns = [[SlideMenu alloc] init];
//
leftScroll = [slidebtns initLeftImagesWithFrameColor: self.view];
// 
rightScroll = [slidebtns initRightImagesWithFrameColor: self.view];
//
[slidebtns release];
where the

Code:
UIImageView *leftScroll;
UIImageView *rightScroll;
as part of the crunchviewcontroller.

Which calls this function inthe scrollview class

Code:
-(UIImageView *)initLeftImagesWithFrameColor: (UIView *)view {
leftMenuImage = [[UIImageView alloc] initWithFrame:CGRectMake(7, 208, 25, 68)];
leftMenuImage.image = [UIImage imageNamed:@"button_prev.png"];
leftMenuImage.opaque = YES;
//
[view addSubview:leftMenuImage];
//
return leftMenuImage;
}
which gives a pointer to the next and prev Images.
famictech2000 is offline   Reply With Quote
Old 05-18-2011, 09:35 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 21
famictech2000 is on a distinguished road
Default

Quote:
Originally Posted by Meredi86 View Post
So he first thing i would suggest to check is this:

Do you have in your xib file the imageVews for both left and right images or are they completely created in the program? I ask because if i want to hide something in this fashion then i have an IBOutlet for whatever element it is so in your case:
Code:
@property (nonatomic, retain) IBOutlet UIImageView* rightMenuImage;
@property (nonatomic, retain) IBOutlet UIImageView* leftMenuImage;
And then have these hooked up in interface builder.

If all three of those nslogs are showing then at least you know that you are evaluating correctly, there is just something wrong in the use of the image view
Hello

I reworked the class alittle to see if that woudl change things and I did as you said

Code:
@property (nonatomic, retain) IBOutlet UIImageView* rightMenuImage;
@property (nonatomic, retain) IBOutlet UIImageView* leftMenuImage;
But now you say :
Quote:
And then have these hooked up in interface builder.
Is there a way to code this instead of using IB!? I so want to keep everything at a code level and don't want to use Interface builder?!

Thanks for you help!
famictech2000 is offline   Reply With Quote
Old 05-19-2011, 03:13 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

Ah the age old code vs IB approach. Unfortunately i cant help outside IB as i do use it and havnt done a huge amount without it. Sorry
Meredi86 is offline   Reply With Quote
Old 10-20-2011, 10:43 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2009
Posts: 113
jonusx is on a distinguished road
Default

Code:
-(UIImageView *)initLeftImagesWithFrameColor: (UIView *)view {
leftMenuImage = [[UIImageView alloc] initWithFrame:CGRectMake(7, 208, 25, 68)];
leftMenuImage.image = [UIImage imageNamed:@"button_prev.png"];
leftMenuImage.opaque = YES;
//
[view addSubview:leftMenuImage];
//
return leftMenuImage;
}
I think your issue may be the fact that you add the the subview in the method above. Try adding it when the method returns. The code I can see seems overly complicated for view setup. You could also try [leftMenuImage setHidden:YES]; when you want to hide it

Also, that slidebtns class... is that a class with methods just for creating those buttons?
__________________
What do you have to share? Share and view pics Oneshare

Play Magic: The Gathering? Try The Sylvan Archives!

Warhammer 40k your thing? W40k Manager is your thing.

Like karaoke? Try iSing Karaoke Locator

Last edited by jonusx; 10-20-2011 at 10:49 PM.
jonusx is offline   Reply With Quote
Reply

Bookmarks

Tags
scroll issue, scroll 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: 397
20 members and 377 guests
Absentia, AyClass, baja_yu, checkright, Diligent, dre, fvisticot, givensur, jbro, jPuzzle, momolgtm, Newbie123, Paul10, Punkjumper, revg, sacha1996, skrew88, taylor202, tomtom100
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,643
Threads: 94,110
Posts: 402,858
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Diligent
Powered by vBadvanced CMPS v3.1.0

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