Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't my string display in a UIAlertView
    primarykey
    data
    text
    <p>First, I have thoroughly researched this and not been able to find anything matching what I'm looking for.</p> <p>My problem is this: I have a string property created in Class1 and then synthesized as shown below.</p> <pre><code>@interface Class1 : UIViewController { NSString *testvar; } @property (nonatomic, retain) NSString *testvar; @end @implementation Class1 @synthesize testvar - (void)viewDidLoad { [super viewDidLoad]; self.testvar = @"Test variable"; } @end </code></pre> <p>This works fine for defining the variable/property's value as it works in a test <code>UIAlertView</code> displayed by the same <code>viewDidLoad</code> method it is defined in. The problem occurs when the other class, Class2, makes an attempt to retrieve and use the property. The code used in the second class is as follows:</p> <pre><code>Class1 *foo = [[Class1 alloc]init]; UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Title" message:foo.testvar delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; [foo release]; </code></pre> <p>What happens is that the <code>UIAlertView</code> displays, but has no message. I believe that the value of the Class1 testvar property is being released before Class2 attempts to retrieve it, or I am setting it incorrectly. I say this because I tried the same thing, but used an int instead of <code>NSString</code>. I set the int's value to 3 in Class1's <code>viewDidLoad</code> and when the <code>UIAlertView</code> displayed, it showed the int's value, but displayed "0", the default value of the int, rather than my set value.</p> <p>Being relatively new to Objective-C and not yet having an excellent grasp of memory management, I think the error has something to do with where or how I set the value of my property. Any insight would be appreciated. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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