Iphone 为什么会崩溃:stringByAppendingFormat
我的代码在此函数处崩溃(在stringByAppendingFormat:with errorIphone 为什么会崩溃:stringByAppendingFormat,iphone,string,crash,Iphone,String,Crash,我的代码在此函数处崩溃(在stringByAppendingFormat:with errorobjc_msgSend()选择器名称:stringByAppendingFormat) 这就是那句话: // imagesPath = ...iPhone Simulator/4.0/Applications/NUMBERS/Documents/images UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath
objc_msgSend()选择器名称:stringByAppendingFormat
)
这就是那句话:
// imagesPath = ...iPhone Simulator/4.0/Applications/NUMBERS/Documents/images
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[imagesPath stringByAppendingFormat:@"/%d.png", [[self.postsArrayID objectAtIndex:row] intValue]]];
这可能与保留物品有关吗
谢谢:)通常,
objc\u msgSend()
中的崩溃意味着传递给对象的消息(在本例中,stringByAppendingFormat
)不是为该对象指定的。揭示了stringByAppendingFormat
的许多顶级页面都非常陈旧,由此推断该API可能已被弃用,取而代之的是其他内容
作为一种解决方法,它似乎是您用例的可行替代方案。为什么不使用
stringByAppendingPathComponent:
?当然imagesPath
不是../NUMBERS/images
?它不是<代码>图像吗
> rootPath =
> [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
> NSUserDomainMask, YES)
> objectAtIndex:0]; imagesPath =
> [rootPath
> stringByAppendingPathComponent:@"/images/"];
哈!设置属性和设置
使用self.imagesPath=。。。固定的
信息技术Obj-c很难理解
有时
用于设置获取路径的方法是自动删除的,因此当您稍后尝试访问它们时,这些方法已经失效。使用self.imagesPath属性将保留数据(您将其指定为(非原子,retain)),因此它将一直保留,直到您释放它为止(或使用属性访问器self.imagesPath=
强烈推荐使用苹果的《内存管理指南》,尽管读了几遍之后仍然很容易失败。:-给出更多的代码。
imagesPath
的类型是什么?(它不是NSArray*
或其他名称复数形式的集合吗?)如何初始化此变量?如前所述,imagesPath
可能不是NSString
-请尝试NSLog(@“%d”,[imagesPath是kindof类:[NSString类]];
验证。imagesPath实际上是一个NSString,在标题中声明。声明为NSString
并不意味着您为它分配了字符串。另一种可能是它已经在某个地方被释放,并且没有设置为nil
。您复制的行在技术上没有错误,因此需要更多信息。导致中断的异常是什么?崩溃记录了什么?另外,您可能希望将代码扩展到几行,以查看是哪种方法导致了崩溃,我看不出它已被弃用。stringWithFormat不起作用。我想将字符串附加到另一个字符串。UIImage*image=[[UIImage alloc]initWithContentsFile:[NSString stringWithFormat:@“%@/%d.png”,imagesPath,[[self.postsArrayID objectAtIndex:row]intValue]];
stringByAppendingFormat
未在文档中作为NSString的类方法列出。@FalconScreek我认为此代码无法正常工作无论是imagesPath
还是OP所期望的。当然,这可能会修复崩溃或将其移动到其他地方。而且stringByAppendingFormat
是一个实例方法,正如名称所示,我现在正在使用它。这没关系,不是吗?我没有设置那个值,它只是向您解释它是如何构建的。我会读我的t、 你有链接吗?我以前有过几次这样的崩溃:pSure,这里是链接:我想他们在iPhone文档中有它的精确副本。