In the control page sample from the apple, there is a ScrollView in the interface builder. It is associated with the corresponding IBOutlet. I want to change the code so that all this is done programmatically. I delete the object of the interface builder, I delete the IBOutlet keyword. I select and run scrollView, but nothing appears when the program starts.
I assume this is due to the fact that I need to assign it as a subView for the main view. Or me? I still do not understand how all views work and interact with each other. If I do [self.view addSubView:ScrollView]; I get a runtime error (or something, usually it just says something like BAD ACCESS or SIGABRT).
What am I doing wrong? Am I on the wrong track? (only two days in ios programming, still a little lost in the forest)
awakeFromNib in the phone content controller:
- (void)awakeFromNib { scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
header file:
AppDelegate:
#import "AppDelegate.h" #import "ContentController.h" @implementation AppDelegate @synthesize window, contentController; - (void)dealloc { [window release]; [contentController release]; [super dealloc]; } - (void)applicationDidFinishLaunching:(UIApplication *)application { NSString *nibTitle = @"PadContent"; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { nibTitle = @"PhoneContent"; } [[NSBundle mainBundle] loadNibNamed:nibTitle owner:self options:nil]; [self.window addSubview:self.contentController.view]; [window makeKeyAndVisible]; } @end
and scrollView has been removed from the xib file. Note. This is a new version of the downloaded program, in which all I changed is removing the IBOutlet keyword for scrollView, removing the scroll from xib and adding a selection line, initialization in awake from nib.
I had suggestions for changing appDelegate and changing awakeFromNib to the init method, I tried all this, but it still doesn't work.
source share