2012-05-14 9 views
3

apple初心者はここに。私は現在、nickLockwoodによってiCarouselを勉強して試しています。私はiCarouselに画像を置くことを計画しています。だからここに私の.mと.hのコードです:iCarouselの読み込みに問題がある

// .M

@implementation ViewController 

@synthesize images; 
... 

- (void)awakeFromNib 
{  
    if (self) { 

     //set up carousel data 
     //wrap YES = infinite loop 
     wrap = YES; 

     self.images = [NSMutableArray arrayWithObjects: 
         @"apple.jpg",@"lemon.jpg",@"orange.jpg",@"melon.jpg",@"mango.jpg",nil];  
      } 

} 


- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    if (view == nil) 
{ 

     view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[images objectAtIndex:index]]]; 
} 
    return view; 

} 

// .hの

@interface ViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>{ 

NSMutableArray *images; 
... 
} 
@property (nonatomic,retain) NSMutableArray *images; 
… 
@end 

私はコードになりたいので、私は30枚の画像を追加することを計画しました。維持可能。 私の問題は、NSBundleまたはアプリケーションディレクトリからイメージを取得したいのですが、私は別のコードを試しましたが、イメージがカルーセルに表示されません。ご協力いただきありがとうございます。

+0

デリゲートとデータソースを設定しましたか?それは私が見たように良いです – adali

+0

はい私はすでにそれを設定しました。 – Bazinga

+0

あなたの問題は何ですか、ビューが表示されない、または空のビューのみですか? – adali

答えて

1

ここで私のiCarouselアプリケーションで使用している私のコードです。いくつかの方法が欠けています。だからここにいるのです。

#pragma mark iCarousel methods 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
    return [items count]; 
} 

- (NSUInteger)numberOfVisibleItemsInCarousel:(iCarousel *)carousel 
{ 
    //limit the number of items views loaded concurrently (for performance reasons) 
    //this also affects the appearance of circular-type carousels 
    return 7; 
} 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]]; 
    return view; 

} 

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel 
{ 
    //note: placeholder views are only displayed on some carousels if wrapping is disabled 
    return 0; 
} 

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
    view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[items objectAtIndex:index]]]; 
    return view; 

} 

- (CGFloat)carouselItemWidth:(iCarousel *)carousel 
{ 
    //usually this should be slightly wider than the item views 
    return ITEM_SPACING; 
} 

- (CGFloat)carousel:(iCarousel *)carousel itemAlphaForOffset:(CGFloat)offset 
{ 
    //set opacity based on distance from camera 
    return 1.0f - fminf(fmaxf(offset, 0.0f), 1.0f); 
} 

- (CATransform3D)carousel:(iCarousel *)_carousel itemTransformForOffset:(CGFloat)offset baseTransform:(CATransform3D)transform 
{ 
    //implement 'flip3D' style carousel 
    transform = CATransform3DRotate(transform, M_PI/8.0f, 0.0f, 1.0f, 0.0f); 
    return CATransform3DTranslate(transform, 0.0f, 0.0f, offset * carousel.itemWidth); 
} 

- (BOOL)carouselShouldWrap:(iCarousel *)carousel 
{ 
    return wrap; 
} 
- (void)carouselDidEndScrollingAnimation:(iCarousel *)aCarousel 
{  
    [labelDescription setText:[NSString stringWithFormat:@"%@", [descriptions objectAtIndex:aCarousel.currentItemIndex]]]; 
} 

これが役に立ちます。

+0

メインバンドルはどうですか? – Bazinga

+0

よろしいですか?carousel.type = iCarouselTypeCoverFlow2を追加してください。あなたのviewDidLoad – Mou

+0

はすでに完了しています。私の問題は、NSBundleまたはカメラロールから画像をアップロードすることです。ありがとう – Bazinga

関連する問題