程序在使用除NSLOG之外的变量时收到SIGABRT

时间:2011-05-20 11:26:03

标签: iphone objective-c xcode ios

嘿伙计们,我在尝试将实例变量用于NSLOG以外的任何东西时都收到了SIGABRT:

//Class_X.H
@interface MeldingController : UIViewController 
{   
    NSString *refURLAsString;
}
@property (nonatomic, retain) NSString *refURLAsString;

//Class_X.M
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    self.refURLAsString = [info objectForKey:UIImagePickerControllerReferenceURL];
    NSLog(@"%@",self.refURLAsString);//Successfully outputs the ReferenceURL string
}

-(void)function_abc
{
    NSLog(@"%@",self.refURLAsString);//Successfully outputs the ReferenceURL string
    NSURL *URL = [NSURL URLWithString:self.refURLAsString]; //SIGABRT
    //Or even trying to make another string using refUrlAsString 
    NSString *string = [[NSString alloc]init];
    string = self.refURLAsString;//SIGABRT
}

iPhone模拟器iOS版本4.3,Xcode 4。

任何想法?欢呼声。

5 个答案:

答案 0 :(得分:3)

您的refURLAsString类型为NSString *,但[info objectForKey:UIImagePickerControllerReferenceURL]应返回NSURL *个实例according to the docs。你想要:

self.refURLAsString = [[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];

NSLog的工作原因是因为它通过description序列调用每个要打印的对象上的%@方法,并确实返回一个字符串。但refURLAsString指向NSURL而不是NSString,这会导致[NSURL URLWithString:self.refURLAsString];崩溃。

答案 1 :(得分:0)

试试这个

string =[refURLAsString copy];

答案 2 :(得分:0)

您的代码正在搞砸refURLAsString。我不能告诉你如何从发布的代码。有关详细信息,请激活NSZombieEnabled

答案 3 :(得分:0)

不确定问题究竟是什么,但请尝试string = [NSString stringWithFormat:@"%@",self.refURLAsString];,看看它是否也崩溃了

答案 4 :(得分:0)

NSString * string = [NSString stringWithFormat:@"%@",self.refURLAsString];

无需在此分配