1

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

Kevin
  • 193
  • 2
  • 3
  • 10

5 Answers5

2
  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.
UIAdam
  • 5,303
  • 1
  • 27
  • 23
  • Hi there, I think your answer number (2) has almost helped me to solve my issue. This program i am creating is based off the PageControl example which immediately loads the scrollview upon program execution and performs the scrollview setup in the - (void)awakeFromNib. My program is different where the View with scrollview is only created when the user clicks on a button. However, I am not able to synthesise the scrollview (get a correct memory pointer) in the - (void)awakeFromNib, unlike the standard pagecontrol example. But i have noticed that it works for me in - (void)viewDidLoad – Kevin Jan 12 '12 at 05:38
  • Any idea why mine does not work in ' - (void)awakeFromNib' but works in '- (void)viewDidLoad' ? – Kevin Jan 12 '12 at 05:41
  • http://stackoverflow.com/questions/377202/which-should-i-use-awakefromnib-or-viewdidload – UIAdam Jan 12 '12 at 06:07
1

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.

Daniel
  • 22,363
  • 9
  • 64
  • 71
0

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.

Sourabh Bhardwaj
  • 2,524
  • 1
  • 17
  • 19
0

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.

OdNairy
  • 540
  • 4
  • 15
-2

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.

Nikola K.
  • 7,093
  • 13
  • 31
  • 39