
我有一个帮助程序类,它获取我的数据库的路径.我在app delegate中分配了这个类. RootVIEwController获取对appDelegate的引用,如下所示:
//insIDe .h file@interface RootVIEwController : UItableVIEwController<UItableVIEwDelegate,UItableVIEwDataSource>{NSArray *controllers;myAppDelegate *appDelegate;}//insIDe .m file@implementation RootVIEwController@synthesize controllers;- (voID)vIEwDIDLoad {appDelegate = [[UIApplication sharedApplication] delegate]; self.controllers = appDelegate.topicControllers;[super vIEwDIDLoad];} 我将鼠标移到appDelegate上以查找数据库助手类和包含数据库路径的属性:
NSPathStore2 * appDelegate.databaseHeper.databasePath "/Users/userA/library/Application Support/iPhone Simulator/User/Applications..."
databasePath声明为Nsstring.为什么它改为NSPathStore2?
当我继续在调试器中发生一些其他奇怪的事情.一旦我进入vIEwWillAppear,属性值变为“无效”,类型返回Nsstring.虽然我甚至在那里见过UIbutton.
为什么它变为无效?我不能再使用变量了.
- (voID)vIEwWillAppear:(BOol)animated {[super vIEwWillAppear:animated]; //changes before this line executes} 我在vIEwDIDLoad和vIEwWillAppear之间没有做任何事情.以下是在databaseHelper类中分配databasePath的方法,该类在applicationDIDFinishLaunching上发生:
- (Nsstring *) getDBPath {NSArray *paths = NSSearchPathForDirectorIEsInDomains(NSdocumentDirectory,NSUserDomainMask,YES);Nsstring *documentsDir = [paths objectAtIndex:0];return [documentsDir stringByAppendingPathComponent:self.databasename];} stringByAppendingPathComponent返回Nsstring.为什么我会在分配后的某个时间获得NsstorePath2?
我现在所有工作都没有问题但只是调用[databaseHelper getDBpath].我的目标是节省一些cpu周期并存储该值.因此databasePath.有关databasePath更改为无效的任何建议吗?
解决方法 因为你没有保留这个价值.查看 Memory Management Programming Guide中的规则,了解何时需要保留某些内容.当然,正如cdespinosa所说,你可能不需要首先缓存这个路径名.它可能不是一个重要的性能杀手.首先介绍,然后优化热点.
总结以上是内存溢出为你收集整理的iphone – 为什么NSString属性更改为无效值?全部内容,希望文章能够帮你解决iphone – 为什么NSString属性更改为无效值?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)