Iphone 使用NSLOG以外的变量时,程序收到SIGABRT
嘿,伙计们,我在尝试将实例变量用于NSLOG以外的任何对象时收到了SIGABRT:Iphone 使用NSLOG以外的变量时,程序收到SIGABRT,iphone,objective-c,xcode,ios,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:(UIImagePic
//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
有什么想法吗?干杯。试试这个
string =[refURLAsString copy];
试试这个
string =[refURLAsString copy];
你的代码搞砸了加油系统。我不能告诉你如何从张贴的代码。激活以获取详细信息。您的代码正在破坏加油管柱。我不能告诉你如何从张贴的代码。激活以获取详细信息。不确定问题到底是什么,但请尝试
string=[NSString stringWithFormat:@“%@”,self.refURLAsString]
并查看它是否也在此处崩溃不确定到底是什么问题,但请尝试string=[NSString stringWithFormat:@“%@”,self.refURLAsString]代码>并查看它是否也在此处崩溃NSString*string=[NSString stringWithFormat:@“%@”,self.refURLAsString]
无需在此分配NSString*string=[NSString stringWithFormat:@“%@”,self.refURLAsString]
无需在此处分配您的refURLAsString
类型为NSString*
,但[info objectForKey:UIImagePickerControllerReferenceURL]
应返回NSURL*
实例。你想要:
self.refURLAsString = [[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
NSLog
工作的原因是,它对通过%@
序列打印的每个对象调用description
方法,并且返回字符串。但是refURLAsString
指向的是NSURL而不是NSString,这使得[nsurlUrlWithString:self.refURLAsString]代码>崩溃。您的refURLAsString
类型为NSString*
,但[info objectForKey:UIImagePickerControllerReferenceURL]
应返回NSURL*
实例。你想要:
self.refURLAsString = [[info objectForKey:UIImagePickerControllerReferenceURL] absoluteString];
NSLog
工作的原因是,它对通过%@
序列打印的每个对象调用description
方法,并且返回字符串。但是refURLAsString
指向的是NSURL而不是NSString,这使得[nsurlUrlWithString:self.refURLAsString]代码>崩溃