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

Reply
 
LinkBack Thread Tools Display Modes
Old 08-31-2011, 06:11 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 12
Lith is on a distinguished road
Unhappy A extremely strange problem about UIScrollView

I just want to add a UIScrollView into my project, so I created a UIViewController class and added code below:

Code:
@interface TestScrollViewController : UIViewController<UIScrollViewDelegate> {
    IBOutlet UIScrollView *scrollView;
    UIImageView *imageView;
    
}
@property(nonatomic,retain)UIScrollView *scrollView;
@property(nonatomic,retain)UIImageView *imageView;

@end
and I added codes in the method of ViewDidLoad


Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"testScrollView.png"]];
    self.imageView = tempImageView;
    [tempImageView release];
    
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
    scrollView.maximumZoomScale = 4.0;
    scrollView.minimumZoomScale = 0.75;
    scrollView.clipsToBounds = YES;
    scrollView.delegate = self;
    scrollView.hidden = NO;
    scrollView.showsVerticalScrollIndicator = YES;
    [scrollView addSubview:imageView];
    self.view = scrollView;
 
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}

However it returns me just a blank screen, I also tried a lot of simple code about UIScrollView, but they don't work neither.

BTW I use the ViewController in a tabbar:

Code:
TestScrollViewController * vc2 = [[TestScrollViewController alloc] init];
 vc2.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"Test" image:[UIImage imageNamed:@"my24.png"] tag:1];
/*
blablabla
*/
NSArray* controllers = [NSArray arrayWithObjects:nav1, vc2, nav3,vc4,nil];
myTabbarController.viewControllers = controllers;

Anyone could help?
Lith is offline   Reply With Quote
Old 08-31-2011, 06:19 AM   #2 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

Code:
    self.view = scrollView;
why?!

you should do
Code:
[self.view addSubView:scrollView];
And however you should alloc\init scrollview before do it. if you added the scrollview with IB, so you don't need to addSubView or change self.view
__________________
dany_dev is offline   Reply With Quote
Old 08-31-2011, 07:38 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 12
Lith is on a distinguished road
Post

Quote:
Originally Posted by dany_dev View Post
Code:
    self.view = scrollView;
why?!

you should do
Code:
[self.view addSubView:scrollView];
And however you should alloc\init scrollview before do it. if you added the scrollview with IB, so you don't need to addSubView or change self.view
Yes, I actually tried that before, I tried this code:


Code:
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"testScrollView.png"]];
    self.imageView = tempImageView;
    [tempImageView release];
    
    scrollView = [[UIScrollView alloc]init];
    scrollView.contentSize = CGSizeMake(imageView.frame.size.width, imageView.frame.size.height);
    scrollView.maximumZoomScale = 4.0;
    scrollView.minimumZoomScale = 0.75;
    scrollView.clipsToBounds = YES;
    scrollView.delegate = self;
    scrollView.hidden = NO;
    scrollView.showsVerticalScrollIndicator = YES;
    [scrollView addSubview:imageView];
    [self.view addSubview:scrollView];
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
    return imageView;
}
but it turns out an infinite loop,that is the strange place.

Lith is offline   Reply With Quote
Old 08-31-2011, 07:45 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 12
Lith is on a distinguished road
Unhappy

Quote:
Originally Posted by dany_dev View Post
Code:
    self.view = scrollView;
why?!

you should do
Code:
[self.view addSubView:scrollView];
And however you should alloc\init scrollview before do it. if you added the scrollview with IB, so you don't need to addSubView or change self.view

and also, it shows that this line [self.view addSubView:scrollView] cause the infinite loop.
Lith is offline   Reply With Quote
Old 08-31-2011, 07:51 AM   #5 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 12
Lith is on a distinguished road
Default

Quote:
Originally Posted by Lith View Post
and also, it shows that this line [self.view addSubView:scrollView] cause the infinite loop.
Ah!!!!!!!!
I finally solve the problem, the [self.view addSubView: scrollView] causes the problem, but the self.view = scrollView didn't, however, I really don't know why~

ThX all the same!!!
Lith is offline   Reply With Quote
Old 08-31-2011, 08:58 AM   #6 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

however it is an incorrect way to use UIViewController.

The problem maybe is generated by you modifying something in IB..
__________________
dany_dev is offline   Reply With Quote
Old 08-31-2011, 08:41 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 12
Lith is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
however it is an incorrect way to use UIViewController.

The problem maybe is generated by you modifying something in IB..
T^T,but, I didn't use nib file with this VC
Lith is offline   Reply With Quote
Reply

Bookmarks

Tags
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: 399
5 members and 394 guests
JackReidy, jeroenkeij, Sami Gh, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,671
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, JackReidy
Powered by vBadvanced CMPS v3.1.0

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