Hi guys,
So I am busy reading a book by Apress: iOS 6 Programming.
Really enjoying the book at the moment and learning a great deal.
However, I do have a question regarding the book's code.
In the book - we create 5 buttons with drag-to-code method from the .xib file - the outlets are properties in the header file. No problem there (Unless we wanted them to be private, of course )
Here is the code the book uses for positioning theseGUI objects on the screen during different rotations of the device:
So, this code access the ivars directly. Which from what I read should never be done, unless we are impliementing our getter or setter, right?
So I tweaked the code to my understanding:
Here I am accessing the ivars using
Of course, both versions work. My question is which way is "more correct" here and why?
Thanks.
So I am busy reading a book by Apress: iOS 6 Programming.
Really enjoying the book at the moment and learning a great deal.
However, I do have a question regarding the book's code.
In the book - we create 5 buttons with drag-to-code method from the .xib file - the outlets are properties in the header file. No problem there (Unless we wanted them to be private, of course )
Here is the code the book uses for positioning theseGUI objects on the screen during different rotations of the device:
Code:
- (void)doLayoutForOrientation:(UIInterfaceOrientation)orientation {
if (UIInterfaceOrientationIsPortrait(orientation)) {
_bigButton.frame = CGRectMake(20, 20, 280, 280);
_actionButton1.frame = CGRectMake(20, 320, 120, 40);
_actionButton2.frame = CGRectMake(20, 400, 120, 40);
_actionButton3.frame = CGRectMake(180, 320, 120, 40);
_actionButton4.frame = CGRectMake(180, 400, 120, 40);
} else {
_bigButton.frame = CGRectMake(20, 20, 260, 260);
_actionButton1.frame = CGRectMake(320, 20, 120, 40);
_actionButton2.frame = CGRectMake(320, 90, 120, 40);
_actionButton3.frame = CGRectMake(320, 160, 120, 40);
_actionButton4.frame = CGRectMake(320, 230, 120, 40);
} }
So, this code access the ivars directly. Which from what I read should never be done, unless we are impliementing our getter or setter, right?
So I tweaked the code to my understanding:
Code:
-(void)doLayoutForOrientation:(UIInterfaceOrientation)orientation
{
if (UIInterfaceOrientationIsPortrait(orientation)){
self.bigButton.frame = CGRectMake(20, 20, 280, 280);
self.actionButton1.frame = CGRectMake(20, 320, 120, 40);
self.actionButton2.frame = CGRectMake(20, 400, 120, 40);
self.actionButton3.frame = CGRectMake(180, 320, 120, 40);
self.actionButton4.frame = CGRectMake(180, 400, 120, 40);
}else{
self.bigButton.frame = CGRectMake(20, 20, 260, 260);
self.actionButton1.frame = CGRectMake(320, 20, 120, 40);
self.actionButton2.frame = CGRectMake(320, 90, 120, 40);
self.actionButton3.frame = CGRectMake(320, 160, 120, 40);
self.actionButton4.frame = CGRectMake(320, 230, 120, 40);
}
}
Here I am accessing the ivars using
Code:
self.propertyName.
Of course, both versions work. My question is which way is "more correct" here and why?
Thanks.