首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >icarousel未显示

icarousel未显示
EN

Stack Overflow用户
提问于 2012-10-23 17:09:39
回答 1查看 1.2K关注 0票数 1

我将iCarousel添加到我的应用程序中,但它不起作用。在我的其他应用程序中,它可以正常工作。我在InterfaceBuilder中链接了视图、委托和数据源

ViewController.h

代码语言:javascript
复制
#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

代码语言:javascript
复制
#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

你知道我做错了什么吗?我看到一片空虚的景象...

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-24 04:26:42

您是否尝试过在数据源方法中设置断点,以查看它们是否被调用?

如何使用调试器检查在iCarousel视图上是否正确设置了carousel的dataSource属性?

我的猜测是dataSource没有被正确绑定,但是如果没有更多的信息就很难确定。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13027021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档