ios - Global NSString without alloc access only in 2 place or in two method and in 3rd place it crash the application -
here nsstring *documentspath
declare in globally.
#import "detailviewcontroller.h" #import "information.h" @interface detailviewcontroller () { nsstring *documentspath; nsarray *paths; }
assigning , accessing in viewdidload method.
- (void)viewdidload { nslog(@"enter viewdidload detailviewcontroller"); paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes); **documentspath** = [paths objectatindex:0]; nsstring *plistpath = [**documentspath** stringbyappendingpathcomponent:@"infodetail.plist"]; }
also accessing in settingcellimage
method
-(void)settingcellimage:(uitableviewcell *)cell noofrow:(int)row { nslog(@"enter in settingcellimage method"); nslog(@"doc path cell ===>%@",documentspath); nsstring *imagepath = [**documentspath** stringbyappendingformat:[nsstring stringwithformat:@"/%d.png",row]]; }
but when use in didselectrowatindexpath
method crash application.
(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { information *information = [[[information alloc]initwithnibname:@"information" bundle:nil]autorelease]; information.infodict = [test objectatindex:indexpath.row]; nslog(@"selected row no ==> %d",indexpath.row); nslog(@"using @=== %d",indexpath.row); nslog(@"documents path == %@",**documentspath**);// here gives exe_bad_access. nsstring *selectedimagepath = [documentspath stringbyappendingformat:[nsstring stringwithformat:@"/%d.png",indexpath.row+1]]; }
i'm new in iphone development , demo project. please me possible. , please give me answer in easy way can understand fast. , yes know i'm not alloc init
documentspath direct assign in viewdidload
method, , want know why access in 2 places , in 3rd place crash application. hope can me. thank you!
since you're not using arc, have make sure retain/releasing/autoreleasing objects. what's happening documentspath got released , accessing released object. assign string so:
documentspath = [[nsstring stringwithstring:[paths objectatindex:0]] retain];
and have release in dealloc call.
Comments
Post a Comment