我完全不熟悉iPhone开发,基本上任何C语言。我理解变量等的概念,所以我试图以基本方式使用它们来更好地理解这个概念。不幸的是,当我尝试做一些非常简单的事情时,我收到了编译器警告:我只想分配我的5个变量值。
ViewController.h代码:
@interface MyApplicationViewController : UIViewController {
从不兼容的指针类型分配?
IBOutlet UITextView *variable1;
IBOutlet UITextView *variable2;
IBOutlet UITextView *variable3;
IBOutlet UITextView *variable4;
IBOutlet UITextView *variable5;
}
[我知道,理论上我可以连接这些变量的文本在IB的看法,但我不]
@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代码:
@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]
}
我不取消分配我的变量,因为我想让他们在内存中unti l应用程序被完全终止。为什么我会收到这些警告?我做错了什么?我打算在这里做的是将变量的值(memorytext1,memory text 2等)保存在内存中。我已经看过Stack Overflow上有关此警告的其他对话,但他们的问题似乎与我的不符,尽管警告是一样的。请不要说太复杂,因为我还是这个新手。谢谢!
所以,即使我没有文字视图,这仍然工作?我的意思是,这些值是否仍然存储在内存中? – Reynold 2010-12-18 18:45:59
如果你只想存储字符串值,那么使用NSString对象:NSString * stringVar; ... self.stringVar = @“memory text1”; – Vladimir 2010-12-18 19:12:37