iCarousel 应用程序抛出 Thread1:信号 SIGBRT

Posted

技术标签:

【中文标题】iCarousel 应用程序抛出 Thread1:信号 SIGBRT【英文标题】:iCarousel app throws Thread1: signal SIGBRT 【发布时间】:2013-05-02 09:50:59 【问题描述】:

我做错了什么?? 我总是得到 Thread1: signal SIGBRT 错误.... 我将一个 UIView(将其更改为带有文件所有者的 iCarousel)连接到来自 iCarousel 类型的名为 icrousel 的对象及其代表。当我将它与上述所有应用程序断开连接时(没有它的真正功能)。

h 文件:

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

    @interface ViewController : UIViewController <iCarouselDelegate,iCarouselDataSource>

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

    @end

m 文件:

//
//  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】:

问题出在

- (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;

【讨论】:

调用 MakeKeyAndVisible 时 appdelegate 出现错误 icarousel的控制应该是什么?我应该拖动 UIView 并将其更改为 icarousel 吗? 是的,使用 UIView 作为基类 I 界面构建器。

以上是关于iCarousel 应用程序抛出 Thread1:信号 SIGBRT的主要内容,如果未能解决你的问题,请参考以下文章

iCarousel的简单介绍及应用

iCarousel 重复图像

需要在icarousel中拖放视图

无法滚动 iCarousel 图像

iOS 中 iCarousel 应用的按钮选择事件

带有旋转功能的 icarousel 类。