@Synthesize IBOutlet (UIScrollView) not working

1.3k views Asked by At

This is about an outlet not synthesising correctly (UIScrollView)

In one particular case, i have an interface declared as:

@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
    UIScrollView *scrollView;
}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;

And in the implementation....

@synthesize scrollView;

But in debug mode i see that my self->scrollView always has a 0x0 next to it. Performing operations like

CGRect frame = scrollView.frame;

always returns a origin, height, width of zero (i suspect because it did not synthesise correctly)

Does 0x0 mean that it does not point to any location in memory? Does this mean that it did not synthesize correctly? Could it be that there is a broken link somewhere from the outlet to the scrollview in IB?

Cheers Kevin

5

There are 5 answers

0
OdNairy On

If you want to work with outlets and use there real size that user will see (include navigation bar, tab bar, etc.) you must implement all UI changes at viewWillAppear or viewDidAppear.
Read more about stages of loading view from nib.

0
Daniel On

0x0 means a null pointer, you probably have not tied the scrollView to a scroll view in IB...This means having the viewControllers nib have a scrollView in its view and tied to the outlet.

3
UIAdam On
  1. Make sure that you actually connected a UIScrollView to the outlet.
  2. Keep in mind that scrollView won't be set until after the view has been loaded from the nib.
0
Sourabh Bhardwaj On

Try removing local declaration of scrollview i.e.

@interface VC_Create_Preview : UIViewController <UIScrollViewDelegate> {
    UIScrollView *scrollView;//remove this
}

It may help you. Also while allocating use _scrollView instead of scrollView.

0
Greg Young On

Be sure that you are using the correct class in your code, for example, the first UIViewController you drop into storyboard will have the generic "whateveryourprojectiscalled" UIViewController.

However, the problem for me was that I then had that linked to several other UIViewController, none of which had there own class declared, so the scroller outlet I was writing, is only showing up on the main original UIViewController which is not where I needed it to be. So once I wrote a Custom Class name, and then re wrote the code to accommodate that. The outlet appeared perfectly and worked fine.