【问题标题】:methods defined in xib not working-closed在 xib 中定义的方法没有工作关闭
【发布时间】: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


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 2012-12-24
    • 1970-01-01
    • 2014-01-31
    • 2011-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多