Reputation: 15
I am completely new to iPhone development and basically any C language at all. I understand the concept of variables and so forth, so I'm trying to use them in basic way to get a better grasp on the concept. Unfortunately, I'm getting compiler warnings when I try to do something very simple: I just want to assign my 5 variables values.
ViewController.h code:
@interface MyApplicationViewController : UIViewController {
IBOutlet UITextView *variable1;
IBOutlet UITextView *variable2;
IBOutlet UITextView *variable3;
IBOutlet UITextView *variable4;
IBOutlet UITextView *variable5;
}
[I know that theoretically I could connect those variables to text views in IB, but I'm not]
@property (nonatomic, retain) IBOutlet UITextView *variable1;
@property (nonatomic, retain) IBOutlet UITextView *variable2;
@property (nonatomic, retain) IBOutlet UITextView *variable3;
@property (nonatomic, retain) IBOutlet UITextView *variable4;
@property (nonatomic, retain) IBOutlet UITextView *variable5;
@end
ViewController.m code:
@implementation MyApplicationViewController
@synthesize variable1;
@synthesize variable2;
@synthesize variable3;
@synthesize variable4;
@synthesize variable5;
- (void)viewDidLoad {
variable1 = "memory text1"; [Warning]
variable2 = "memory text2"; [Warning]
variable3 = "memory text3"; [Warning]
variable4 = "memory text4"; [Warning]
variable5 = "memory text5"; [Warning]
}
I do not deallocate my variables because I want to keep them in memory until the application is completely terminated. Why am I getting these warnings? Am I doing anything wrong? All I'm intending to do here is save the variables' values (memorytext1, memory text 2, etc.) in the memory. I've looked at the other conversation about this warning on Stack Overflow, but their problem didn't seem to match mine, although the warning was the same. Please don't say anything too complicated, because I am still new to this. Thanks!
Upvotes: 0
Views: 1837
Reputation: 5079
Vladimir is correct, assuming you are using a NIB file to assign the UITextView properties. If you are not using a NIB your variables will be nil and your strings will not be assigned anywhere.
Upvotes: 0
Reputation: 50707
You are missing the @
at the beginning of the text!
variable1.text = @"memory text1";
variable2.text = @"memory text2";
variable3.text = @"memory text3";
variable4.text = @"memory text4";
variable5.text = @"memory text5";
Upvotes: 0
Reputation: 170839
There're 2 problems:
So correct code to set textfield's text should be
variable1.text = @"text1";
Upvotes: 5