【发布时间】:2012-06-21 14:12:00
【问题描述】:
我使用 icarousel 创建了覆盖流效果,但我添加了两个按钮,而不是通过编程方式在 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
【问题讨论】:
-
因此,如果您在两个“
IBAction”方法中的任何一个中设置断点,它们会命中吗?我看到您正在为“buttonTapped:”选择器分配一个动作,但我看不到您在哪里创建两个“其他”按钮(或分配它们的动作)。我们是否缺少您的更多代码? -
它们是按钮点击功能,但它对coverflow中的按钮执行单独的操作..我是否必须定义我在xib中定义的两个按钮的操作?按钮点击?..跨度>
-
如果我在其下定义了它的抛出预期表达式,但与表达式相关的一切都正常..
标签: iphone ios xcode xib icarousel