我已经使用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
答案 0 :(得分:3)
确保nib文件所有者绝对是GoldViewController。检查您是否已将按钮添加到笔尖作为按钮而不是图像。确保每个相关按钮上的touchupinside操作连接到nib文件所有者中的showhome和showback操作。
如果所有这些都没问题,则可能在显示视图控制器视图时,iCarousel的视图覆盖了按钮视图。 (我似乎回想起iCarousel的一些问题,而不是在运行时将视图布置在与nib中定义的相同的位置,但不记得细节)。要找出 - 在viewWillAppear方法中记录按钮框架和iCarousel视图。