Rectangle 27 0

objective c Default view (as UIScrollView) of UIViewController Can't set its content offset?


@property (nonatomic, weak) IBOutlet UIScrollView *scrollView;
UIView
UIViewController
[[self scrollView] setContentSize:CGSizeMake(1024, 2000)];
[[self scrollView] setContentOffset:CGPointMake(0, 150)];
[[self view] setContentSize:CGSizeMake(123, 123)];)
view

(When you connect the outlet that property declaration should be generated for you by XCode).

An alternative to this (that would avoid the need for casting) would be to set the UIViewController custom class back to UIView in interface builder. Then, insert a new UIScrollView as a subview (simply drag and drop in Interface Builder), connecting the UIScrollView to the UIViewController subclass via an IBOutlet that looks something like:

Hey, thanks again will. Sorry for late reply, I was out for holiday. I tried not using dot notation, the result was same. Anyways, appreciate your help : )

On second thoughts, I don't think that not using dot notation should make any difference. I think casting is your only sensible option if you want the UIViewController's top level view to be a UIScrollView.

Thanks Will, I'm appreciate your help. But, doing such thing might break the application as thousand lines of code were made within this controller and several controller and custom class were wired with it. I can simply do search & replace but prefer not to touch any code for now. If there is not a better solution, I'll do this. Anyway, do you know what cause the problem, why do I have to cast it? Thanks again

Then, in your UIViewController subclass, you can do something like:

Yeah, I'm quite sure I understand exactly what you did there, but casting sounds simpler (and therefore better) to me.

Note
Rectangle 27 0

objective c Default view (as UIScrollView) of UIViewController Can't set its content offset?


- (UIScrollView *)scrollView {
   return (UIScrollView *)self.view;
}

I'm not sure what the best solution is but a quick workaround is to create a method that casts the view in the UIViewController. That is:

Then, instead of referring to the view in the ViewController as self.view, refer to it as self.scrollView.

Note