Hi all,
I've been experimenting with scroll views lately. According to the docs, for it to work we need to specify the scroll view size in our program code. The examples I could find handle it on the viewDidLoad method, like this:
I understand why we need to cast self.view as a UIScrollView (because self.view has no contentSize property on its own). But I found this approach to be a bit complicated and tried to simplify it. Instead of casting self.view to an UIScrollView*, why not just have a property set up and pointing to the UIScrollView? So the viewDidLoad method looks like this
Where self.scroll is declared in the view controller's header as:
And this property is connected to the UIScrollView on my nib file, which, in turn, is connected to the view controller's view outlet.
However, it didn't work. The contentSize property was not set, and I could not scroll my view. My question is, why wouldn't this work? Wouldn't self.view and the scroll property be pointing to the same object?
Thanks for any info on this!
I've been experimenting with scroll views lately. According to the docs, for it to work we need to specify the scroll view size in our program code. The examples I could find handle it on the viewDidLoad method, like this:
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIScrollView* scroll = (UIScrollView*)self.view;
scroll.contentSize = CGSizeMake(320,900);
}
I understand why we need to cast self.view as a UIScrollView (because self.view has no contentSize property on its own). But I found this approach to be a bit complicated and tried to simplify it. Instead of casting self.view to an UIScrollView*, why not just have a property set up and pointing to the UIScrollView? So the viewDidLoad method looks like this
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.scroll.contentSize = CGSizeMake(320,900);
}
Where self.scroll is declared in the view controller's header as:
Code:
@property(nonatomic,retain) UIScrollView* scroll;
And this property is connected to the UIScrollView on my nib file, which, in turn, is connected to the view controller's view outlet.
However, it didn't work. The contentSize property was not set, and I could not scroll my view. My question is, why wouldn't this work? Wouldn't self.view and the scroll property be pointing to the same object?
Thanks for any info on this!