2012-10-23 47 views
1

我添加了iCarousel到我的應用程序,但它does not't工作。在我的其他應用程序它的作品。 我聯繫的觀點,委託和InterfaceBuilder下icarousel未顯示

ViewController.h

#import <UIKit/UIKit.h> 
#import "TermineView.h" 
#import "iCarousel.h" 


@interface ViewController : UIViewController <iCarouselDataSource, iCarouselDelegate>{ 

IBOutlet UIWebView *WebView; 
NSURLRequest *Request; 

... 
} 
... 

@property (nonatomic, retain) IBOutlet iCarousel *carousel; 


@end 

ViewController.m

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

@synthesize carousel; 


- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
carousel.type = iCarouselTypeRotary; 
carousel.center = CGPointMake(160.0, 250.0); 
[self.view addSubview:carousel]; 

} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
self.carousel = nil; 

} 

#pragma mark - 
#pragma mark iCarousel methods 

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel 
{ 
//generate 100 buttons 
//normally we'd use a backing array 
//as shown in the basic iOS example 
//but for this example we haven't bothered 
return 100; 
} 

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view 
{ 
UIButton *button = (UIButton *)view; 
if (button == nil) 
{ 
    //no button available to recycle, so create new one 
    UIImage *image = [UIImage imageNamed:@"page.png"]; 
    button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    button.frame = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height); 
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [button setBackgroundImage:image forState:UIControlStateNormal]; 
    button.titleLabel.font = [button.titleLabel.font fontWithSize:50]; 
    [button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside]; 
} 

//set button label 
[button setTitle:[NSString stringWithFormat:@"%i", index] forState:UIControlStateNormal]; 

return button; 
} 

#pragma mark - 
#pragma mark Button tap event 

- (void)buttonTapped:(UIButton *)sender 
{ 
//get item index for button 
NSInteger index = [carousel indexOfItemViewOrSubview:sender]; 

[[[[UIAlertView alloc] initWithTitle:@"Button Tapped" 
          message:[NSString stringWithFormat:@"You tapped button number %i", index] 
          delegate:nil 
        cancelButtonTitle:@"OK" 
        otherButtonTitles:nil] autorelease] show]; 
} 




@end 

什麼,我做錯了任何想法的數據源? 我看到一個空的視圖....

回答

0

你有沒有嘗試過在你的數據源方法中加入斷點來查看它們是否被調用?

如何使用調試器來檢查傳送帶的dataSource屬性是否已在iCarousel視圖上正確設置?

我的猜測是dataSource未被正確綁定,但很難確定沒有更多信息。

+0

我解決了這個問題,Xcode沒有找到page.png – user1767776

0

請首先檢查NSArray陣列不爲零對於下面的方法寫和數據源和委託方法放斷點後經過編譯和構建....它的工作代碼...

- (void)awakeFromNib 
{ 
    //set up data 
    //your carousel should always be driven by an array of 
    //data of some kind - don't store data in your item views 
    //or the recycling mechanism will destroy your data once 
    //your item views move off-screen 
    self.items = [NSMutableArray array]; 
    for (int i = 0; i < 1000; i++) 
    { 
     [self.items addObject:@(i)]; 
    } 
} 

嘗試它...
謝謝