ios - Getting error using iCarousel -
this icarouselviewcontroller.m
- (void)dealloc { //it's idea set these nil here avoid //sending messages deallocated viewcontroller carousel1.delegate = nil; carousel1.datasource = nil; carousel2.delegate = nil; carousel2.datasource = nil; [carousel1 release]; [carousel2 release]; [items1 release]; [items2 release]; [super dealloc]; }
i getting error saying
'release' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'release'
'release' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'release'
'release' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'release'
'release' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'release'
arc forbids explicit message send of 'dealloc'
and error in code aswell
- (uiview *)carousel:(icarousel *)carousel viewforitematindex:(nsuinteger)index reusingview:(uiview *)view { uilabel *label = nil; //create new view if no view available recycling if (view == nil) { view = [[[uiimageview alloc] initwithframe:cgrectmake(0, 0, 200.0f, 200.0f)] autorelease]; ((uiimageview *)view).image = [uiimage imagenamed:@"page.png"]; view.contentmode = uiviewcontentmodecenter; label = [[[uilabel alloc] initwithframe:view.bounds] autorelease]; label.backgroundcolor = [uicolor clearcolor]; label.textalignment = uitextalignmentcenter; label.font = [label.font fontwithsize:50]; [view addsubview:label]; } else { label = [[view subviews] lastobject]; }
saying
'autorelease' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'autorelease'
'autorelease' unavailable: not available in automatic reference counting mode
arc forbids explicit message send of 'autorelease'
how can clear error.
update
thank answer have 4 error saying use of undeclared identifier imagearray1. , know happening. don't " assume using app's bundle , have 2 arrays of nsstring refer each image: imagearray1 , imagearray2." below 1 of save code , creating directory 1 of directories. note: have 1 nsmutablearray called allimagesarray have declared in header file.
nsarray *directorynames = [nsarray arraywithobjects:@"apple",nil]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; // documents folder (int = 0; < [directorynames count] ; i++) { nsstring *datapath = [documentsdirectory stringbyappendingpathcomponent:[directorynames objectatindex:i]]; if (![[nsfilemanager defaultmanager] fileexistsatpath:datapath]) [[nsfilemanager defaultmanager] createdirectoryatpath:datapath withintermediatedirectories:no attributes:nil error:nil]; //create folder nsstring *folderpath = [documentsdirectory stringbyappendingpathcomponent:@"tops"]; nsdata *imagedata = uiimagepngrepresentation(captureimage.image); time_t unixtime = (time_t)[[nsdate date]timeintervalsince1970]; nsstring *timestamp = [nsstring stringwithformat:@"%ldtopsimage.png",unixtime]; nsstring *filepath = [folderpath stringbyappendingpathcomponent:timestamp]; [imagedata writetofile:filepath atomically:yes]; } }
update 4
this?
- (void)viewdidload { [super viewdidload]; //configure carousel imagearray1 = [[nsmutablearray alloc] init]; nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *documentsdirectory = [paths objectatindex:0]; nsstring *location=@"apple"; nsstring *fpath = [documentsdirectory stringbyappendingpathcomponent:location]; nsarray * directorycontent = [[nsfilemanager defaultmanager] directorycontentsatpath: fpath]; imagearray1 = directorycontent; imagearray2 = [[nsmutablearray alloc] init]; nsstring *location=@"green"; nsstring *fpath = [documentsdirectory stringbyappendingpathcomponent:location]; nsarray *directorycontent = [[nsfilemanager defaultmanager] directorycontentsatpath: fpath]; imagearray2 = directorycontent;
this not icarousel
issue. using statements release
, autorelease
in code. remove it. in arc not need memory management manually. why arc there.
update:
according comments, facing problems in displaying images mutiple carousels. assume using 2 icarousel objects. lets name them carousel1
, carousel2
. also, seems using sandbox saving images. if case, have fetch images sandbox using nsfilemanager
. need keep looking @ how that, code icarousel remain more or less same in case well. here, simplicity case assume using app's bundle , have 2 arrays of nsstring
refer each image: imagearray1
, imagearray2
.
in viewdidload
, set delegate
, datasource objects of each carousel self
carousel1.delegate = self; carousel1.datasource = self; carousel2.delegate = self carousel2.datasource = self;
implement datasource methods accordingly:
- (nsuinteger)numberofitemsincarousel:(icarousel *)carousel { //return total number of items in carousel if (carousel == carousel1) { return [imagearray1 count]; } else { return [imagearray2 count]; } } - (uiview *)carousel:(icarousel *)carousel viewforitematindex:(nsuinteger)index reusingview:(uiview *)view { uilabel *label = nil; //create new view if no view available recycling if (view == nil) { view = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, 200.0f, 200.0f)]; uiimage *image; if (carousel == carousel1) { image = [uiimage imagewithcontentsoffile:[imagearray1 objectatindex:index]]; ((uiimageview *)view).image = image; } else { image = [uiimage imagewithcontentsoffile:[imagearray2 objectatindex:index]]; ((uiimageview *)view).image = image; } } return view; }
Comments
Post a Comment