Iphone NSMutableString始终为;超出范围;?
在我的.h文件中,我有:Iphone NSMutableString始终为;超出范围;?,iphone,nsmutablestring,Iphone,Nsmutablestring,在我的.h文件中,我有: #import <UIKit/UIKit.h> @interface untitled : UIViewController { NSMutableString * sResults; } @property (nonatomic,retain) NSMutableString * sResults; @end 每当我检查sResults时,它都会显示“超出范围”。。我做错了什么?试试这个: - (void)viewDidLoad
#import <UIKit/UIKit.h>
@interface untitled : UIViewController
{
NSMutableString * sResults;
}
@property (nonatomic,retain) NSMutableString * sResults;
@end
每当我检查sResults时,它都会显示“超出范围”。。我做错了什么?试试这个:
- (void)viewDidLoad {
[super viewDidLoad];
self.sResults = [NSMutableString stringWithString:@"Hello"]; //retained in synthesized setter
[self.sResults appendString:@" World"];
}
这是可行的,除了我还必须做[self.sResults appendString:@“World”]。奇怪为什么我要做自我测试?谢谢你需要使用self符号,因为它使用了你写得很好的属性/合成。如果不使用self,则直接访问阵列。
- (void)viewDidLoad {
[super viewDidLoad];
self.sResults = [NSMutableString stringWithString:@"Hello"]; //retained in synthesized setter
[self.sResults appendString:@" World"];
}