0

我已经用 0 个结果搜索了“CFString isNaturallyRTL”。

这些是我的课:

//in .H
@interface myViewController : UIViewController {
UITextField *from;
UITextField *to;
NSString *fromText;
NSString *toText;
}

@property (nonatomic, retain) NSString* fromText;
@property (nonatomic, retain) NSString* toText;
@property (nonatomic, retain) UITextField *from;
@property (nonatomic, retain) UITextField *to;

//in .m
@synthesize from, to;
@synthesize fromText, toText;

viewDidLoad(...) {
  fromText = @"Roma";
  toText   = @"Lecce";
}

- (void) drawRoute {
  if ( ([[from text] length] > 2) && ([[to text] length] > 2) ) 
 {
  fromText = from.text;
  toText = to.text;
    [...]
  }
}

现在,我有一个在按钮触摸时打开的视图,其中包含两个文本框和一个按钮。像这样。

- (void) drawRouteTextboxes {
 from = [[UITextField alloc] initWithFrame: [...] ];
 from.text = fromText;
 from.delegate = self;
 [ctr.view addSubview:from];
 [from release];

    to = [[UITextField alloc] initWithFrame: [...] ];

    [...]

    [searchButton addTarget:self action:@selector(drawRoute) forControlEvents: UIControlEventTouchUpInside];
}

一切正常,编译运行。

我第一次单击 drawRouteTextboxes 时,它会打开我的视图并设置默认文本(“Roma”和“lecce”)。第二次,我打开视图,编辑文本字段并调用 drawRoute。没关系。我第三次调用 drawRouteTextboxes 它返回我这个运行时错误:

*** -[CFString _isNaturallyRTL]: message sent to deallocated instance 0x3a8d140

我不知道问题出在哪里......有人知道解决方案吗?这是我第一次看到这个错误!

谢谢,阿尔贝托。

4

1 回答 1

1

一切正常,编译运行。

如果一切都正确,它将毫无错误地运行。;)

这看起来很可疑:

fromText = from.text; toText = to.text;

如果from.text并且to.text正在返回自动释放的对象或稍后释放的对象,那么上面的内容不会保留字符串,并且很容易导致您看到的过度释放问题。

改为使用self.fromText = from.text;

请注意,NSString*属性几乎总是应该是copy而不是retain

于 2010-12-06T16:32:40.133 回答