0

我使用icarousel创建了coverflow效果,但是我没有在xib中以编程方式添加了两个按钮,并且我定义了出口和动作并为该按钮连接了..但是这些按钮显示为图像并且不起作用...这是我的代码.m 文件

@interface GoldViewController ()<UIActionSheetDelegate>

@property (nonatomic, assign) BOOL useButtons;

@end

@implementation GoldViewController

@synthesize carousel1;

-(IBAction)showhome:(id)sender{

ViewController *sec=[[ViewController alloc]initWithNibName:Nil bundle:Nil];
sec.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:sec animated:YES];

} 

-(IBAction)showback:(id)sender{

CollectionsViewController *sec=[[CollectionsViewController alloc]initWithNibName:Nil bundle:Nil];
sec.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:sec animated:YES];

}


#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
carousel1.type = iCarouselTypeCylinder;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ 
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (NSUInteger)numberOfItemsInCarousel:(iCarousel *)carousel
{
return NUMBER_OF_ITEMS;
}

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{

UIImage *buttonImage=[NSArray arrayWithObjects:[UIImage imageNamed:@"ban.jpg"],
                      [UIImage imageNamed:@"pen.jpg"],
                      [UIImage imageNamed:@"ear1.jpg"],
                      [UIImage imageNamed:@"neck.jpg"],
                      [UIImage imageNamed:@"brac.jpg"],
                      [UIImage imageNamed:@"rings.jpg"],nil];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 250.0f, 320.0f);

[button setImage:(UIImage*)[buttonImage objectAtIndex:index] forState:UIControlStateNormal]; 

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
return button;



}

- (CGFloat)carouselItemWidth:(iCarousel *)carousel
{
return ITEM_SPACING;
}



- (BOOL)carousel:(iCarousel *)_carousel shouldSelectItemAtIndex:(NSInteger)index
{
if (index == carousel1.currentItemIndex)
{
    NSLog(@"Should select current item");
}
else
{
    NSLog(@"Should select item number %i", index);
}
return YES;
 }

- (void)carousel:(iCarousel *)_carousel didSelectItemAtIndex:(NSInteger)index
{
if (index == carousel1.currentItemIndex)
{
    //note, this will only ever happen if useButtons == NO
    //otherwise the button intercepts the tap event
    NSLog(@"Did select current item");
}
else
{
    NSLog(@"Did select item number %i", index);
}
 }

 @end
4

1 回答 1

3

确保 nib 文件的所有者肯定是 GoldViewController。检查您是否确实将按钮作为按钮而不是图像添加到笔尖。确保每个相关按钮上的 touchupinside 操作都连接到 nib 文件所有者中的 showhome 和 showback 操作。

如果所有这些都正常,那么当显示视图控制器视图时,iCarousel 的视图可能会覆盖您的按钮视图。(我似乎记得 iCarousel 没有在运行时将视图布置在与 nib 中定义的相同位置但不记得细节的一些问题)。要找出答案 - 在 vi​​ewWillAppear 方法中记录按钮和 iCarousel 视图的框架。

于 2012-06-21T15:06:06.147 回答