Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In fact there are two models:</p> <h2>THE OLD MODEL</h2> <p>These model was the model before Objective-C 2.0 and inherited from Mac OS X. It still works, but you should not declare properties to modify the ivars. That is:</p> <pre><code>@interface StrokeWidthController : UIViewController { IBOutlet UISlider* slider; IBOutlet UILabel* label; IBOutlet StrokeDemoView* strokeDemoView; CGFloat strokeWidth; } @property (assign, nonatomic) CGFloat strokeWidth; - (IBAction)takeIntValueFrom:(id)sender; @end </code></pre> <p>In this model you do not retain IBOutlet ivars, but you have to release them. That is:</p> <pre><code>- (void)dealloc { [slider release]; [label release]; [strokeDemoView release]; [super dealloc]; } </code></pre> <h2>THE NEW MODEL</h2> <p>You have to declare properties for the IBOutlet variables:</p> <pre><code>@interface StrokeWidthController : UIViewController { IBOutlet UISlider* slider; IBOutlet UILabel* label; IBOutlet StrokeDemoView* strokeDemoView; CGFloat strokeWidth; } @property (retain, nonatomic) UISlider* slider; @property (retain, nonatomic) UILabel* label; @property (retain, nonatomic) StrokeDemoView* strokeDemoView; @property (assign, nonatomic) CGFloat strokeWidth; - (IBAction)takeIntValueFrom:(id)sender; @end </code></pre> <p>In addition you have to release the variables in dealloc:</p> <pre><code>- (void)dealloc { self.slider = nil; self.label = nil; self.strokeDemoView = nil; [super dealloc]; } </code></pre> <p>Furthermode, in non-fragile platforms you can remove the ivars:</p> <pre><code>@interface StrokeWidthController : UIViewController { CGFloat strokeWidth; } @property (retain, nonatomic) IBOutlet UISlider* slider; @property (retain, nonatomic) IBOutlet UILabel* label; @property (retain, nonatomic) IBOutlet StrokeDemoView* strokeDemoView; @property (assign, nonatomic) CGFloat strokeWidth; - (IBAction)takeIntValueFrom:(id)sender; @end </code></pre> <h2>THE WEIRD THING</h2> <p>In both cases, the outlets are setted by calling setValue:forKey:. The runtime internally (in particular _decodeObjectBinary) checks if the setter method exists. If it does not exist (only the ivar exists), it sends an extra retain to the ivar. For this reason, you should not retain the IBOutlet if there is no setter method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload