NSMutableString总是“超出范围”?

时间:2010-11-07 22:39:37

标签: iphone nsmutablestring

在我的.h文件中我有:

    #import <UIKit/UIKit.h>


@interface untitled : UIViewController 
{
    NSMutableString * sResults;
}

@property (nonatomic,retain) NSMutableString * sResults;

@end

在我的.m中我有:

#import "untitled.h"


@implementation untitled

@synthesize sResults;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    sResults = [[NSMutableString alloc] initWithString:@"Hello"];
    [sResults appendString:@" World"];
}

@end

每当我检查sResults时,它都说“超出范围”..我做错了什么?

1 个答案:

答案 0 :(得分:2)

试试这个:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.sResults = [NSMutableString stringWithString:@"Hello"]; //retained in synthesized setter
    [self.sResults appendString:@" World"];
}