Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access @property on another class
    primarykey
    data
    text
    <p>A really noob question here. I have 2 VCs. One is called <code>SGPlayer</code> and another is <code>SGDownloader</code>. Basically I want to change the property of <code>SGDownloader</code> from the first class. I import the <code>SGDownloader</code> class like this:</p> <pre><code>// SGPlayer.h #import &lt;UIKit/UIKit.h&gt; #import "SGDownloader.h" @interface SGPlayer : UIViewController @property (nonatomic, retain) SGDownloader *downloaderClass; </code></pre> <p><code>SGPlayer.m</code> is like this:</p> <pre><code>// SGPlayer.m #import "SGPlayer.h" @interface SGPlayer () @end @implementation SGPlayer @synthesize downloaderClass; </code></pre> <p>I then set the downloadUrl property form the <code>SGDownloader</code> class in an action triggered by <code>UIButton</code> like that:</p> <pre><code>- (IBAction)loadURLButton:(id)sender { [self performSegueWithIdentifier:@"loadMyData" sender:nil]; downloaderClass.downloadURL = [NSURL URLWithString:@"http://www.google.com"]; } </code></pre> <p><code>NSLog</code> gives me (null) on my URL. If I use <code>prepareForSegue</code> method all is fine:</p> <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue identifier] isEqualToString:@"loadMyData"]) { SGDownloader *vc = [segue destinationViewController]; vc.downloadURL = [NSURL URLWithString:@"http://www.google.com"]; } } </code></pre> <p>The thing is <em>I don't want</em> to use <code>prepareForSegue</code> here.</p> <p>I assume I might be misunderstanding the whole concept of how do you transfer the data between classes in Obj-C.</p> <p><strong>Edit:</strong></p> <p>I do have a <em>synthesised</em> property in the <code>SGDownloader</code> class:</p> <pre><code>@interface SGDownloader : UIViewController @property (nonatomic, retain) NSURL *downloadURL; @end </code></pre>
    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.
 

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