-2

これは私のものですiCarouselViewController.m

- (void)dealloc
    {
        //it's a good idea to set these to nil here to avoid
        //sending messages to a deallocated viewcontroller
        carousel1.delegate = nil;
        carousel1.dataSource = nil;
        carousel2.delegate = nil;
        carousel2.dataSource = nil;

        [carousel1 release];
        [carousel2 release];
        [items1 release];
        [items2 release];
        [super dealloc];
    }

というエラーが表示されます

'release' は使用できません: 自動参照カウント モードでは使用できません
ARC は 'release' の明示的なメッセージ送信を禁止します
'release' は使用できません: 自動参照カウント モードで は使用できません自動参照カウント モードでは使用できませんARC は 'release' の 明示的なメッセージ送信を禁止 します 'release' は使用できません: 自動参照カウント モードでは使用できません







このコードのエラーも

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UILabel *label = nil;

    //create new view if no view is available for 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];
    }

言って

「autorelease」は使用できません: 自動参照カウント モードでは使用できません
ARC は「autorelease」の明示的なメッセージ送信を禁止します
「autorelease」は使用できません: 自動参照カウント モードでは使用できません
ARC は「autorelease」の明示的なメッセージ送信を禁止します

このエラーをクリアするにはどうすればよいですか。
更新
回答ありがとうございます宣言されていない識別子imageArray1の使用を示す4つのエラーがあります。そして私はこれが起こっていることを知っています。「アプリのバンドルを使用しているだけだと思います。各画像を参照する NSString の 2 つの配列があります。imageArray1 と imageArray2 です。」以下は、私の保存コードの1つであり、私のディレクトリの1つのディレクトリを作成しています。注: ヘッダー ファイルで宣言した allImagesArray という名前の NSMutableArray は 1 つだけです。

NSArray *directoryNames = [NSArray arrayWithObjects:@"Apple",nil];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder

    for (int i = 0; i < [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;
4

3 に答える 3

3

これはiCarousel問題ではありません。releaseコードで,のようなステートメントを使用autoreleaseしています。それを除く。ARC では、メモリ管理を手動で行う必要はありません。それがARCが存在する理由です。

更新:
コメントによると、複数のカルーセルの画像を表示する際に問題に直面しています。2 つの iCarousel オブジェクトを使用しているとします。それらcarousel1に名前を付けましょうcarousel2. また、画像の保存にサンドボックスを使用しているようです。この場合、 を使用してサンドボックスから画像をフェッチする必要がありますNSFileManager。その方法を検討し続ける必要がありますが、その場合でも iCarousel のコードはほぼ同じままです。ここでは、簡単にするために、アプリのバンドルを使用しているだけでNSString、各画像を参照する との 2 つの配列があるimageArray1と仮定しますimageArray2

では、各カルーセルのデータソース オブジェクトを次のようviewDidLoadに設定します。delegateself

    carousel1.delegate = self;
    carousel1.dataSource = self;
    carousel2.delegate = self
    carousel2.dataSource = self;

それに応じてデータソース メソッドを実装します。

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
    //return the total number of items in the 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 is available for 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;
}
于 2013-08-28T11:18:02.953 に答える
0

これは、プロジェクトで ARC を使用しており、ここで示したコードは使用していないためです。これらのクラスで無効にするには、-fno-objc-arc. これを行うには、ターゲットの [ビルド フェーズ] タブに移動します。[コンパイル ソース] グループで、ファイル (クラス) をダブルクリックし、-fno-objc-arcフラグを追加します。

または、すべてのリリース メッセージを削除することもできます。

于 2013-08-28T11:20:13.850 に答える
0

XCodeプロジェクトを作成するときに、「自動参照カウントを使用する」(ARC)ボックスにチェックを入れているので、実際には非常に簡単です。それを解決するには、ターゲットに移動して(iCarouselだと思います)、この「buldsettings」を実行します ---> Objective-c automaticrefcount :NO

その後、コンパイラが機能するはずです。ARC が行うことは、この作業を自動的に行うことです。そのため、auto release および release ステートメントを記述する必要はありませんが、必要な場合は、私が提案したことを実行してください。それ以外の場合は、これらの release ステートメントと autorelease ステートメントを削除してください。

于 2013-08-28T11:18:07.123 に答える