iCarousel应用程序抛出线程1:信号SIGABRT

时间:2013-05-02 09:51:00

标签: iphone ios xcode icarousel

我做错了什么? 我总是得到Thread1:信号SIGBRT错误.... 我将UIView(将其更改为iCarousel与文件所有者)连接到iCarousel类型的对象icrousel及其代理。当我断开它与以上所有应用程序的运行(没有它的真正功能)。

h file:

///
///
//
#import <UIKit/UIKit.h>
#import "iCarousel.h"

    @interface ViewController : UIViewController <iCarouselDelegate,iCarouselDataSource>

    @property (strong, nonatomic) IBOutlet iCarousel *icarousel;

    @end

m file:

//
//  ViewController.m
//  CarouselTry
//
//  Created by Assaf Grimberg on 5/2/13.
//  Copyright (c) 2013 Assaf Grimberg. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize icarousel;


#pragma mark -
#pragma mark iCarousel methods

-(void)carouselDidScroll:(iCarousel *)carousel{

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Carousel Scroll" message:@"YEH" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
    [alert show];    
}

-(void)carousel:(iCarousel *)carousel didSelectItemAtIndex:(NSInteger)index{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Item selected" message:[NSString stringWithFormat:@"%d", index] delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
    [alert show];
}

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



- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 180, 180)];
    NSString *imageName = [[NSString alloc]initWithFormat:@"%@%d%@", @"gift", index, @".png"];
    [imageView setImage:[UIImage imageNamed:imageName]];

    for (UIView *subview in view.subviews) {
        [subview removeFromSuperview];
    }

    [view addSubview:imageView];

    return view;
}

- (NSUInteger)numberOfPlaceholdersInCarousel:(iCarousel *)carousel
{
    //note: placeholder views are only displayed on some carousels if wrapping is disabled
    return 0;
}

- (UIView *)carousel:(iCarousel *)carousel placeholderViewAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    if (view == nil) {
        view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
    }

    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 180, 180)];
    NSString *imageName = [[NSString alloc]initWithFormat:@"%@%d%@", @"gift", index, @".png"];
    [imageView setImage:[UIImage imageNamed:imageName]];

    for (UIView *subview in view.subviews) {
        [subview removeFromSuperview];
    }

    [view addSubview:imageView];

    return view;
}

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

    icarousel.type = iCarouselTypeLinear;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

1 个答案:

答案 0 :(得分:0)

问题在于

- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 180, 180)];
    NSString *imageName = [[NSString alloc]initWithFormat:@"%@%d%@", @"gift", index, @".png"];
    [imageView setImage:[UIImage imageNamed:imageName]];

    for (UIView *subview in view.subviews) {
        [subview removeFromSuperview];
    }

    [view addSubview:imageView];

    return view;
}

您的代码可能就像这样

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

    UIImageView *imgView = (UIImageView*)view;

    if ( !imgView )
    {
        imgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 180, 180)];
    }

    imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"gift%d.png",index]];

    return imgView;
}