0

这真让我抓狂!

我正在看 :

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' * First throw call stack: (0x28f9012 0x271ee7e 0x28acb6a 0x28aca20 0x5866c 0x5eeee 0x154f103 0x154f42b 0x155cf80 0x1564fad 0x156589b 0x1565e93 0x1565a88 0x8628 0x2732705 0x146f2c0 0x16aba64 0x2732705 0x146f2c0 0x146f258 0x1530021 0x153057f 0x152f6e8 0x149ecef 0x149ef02 0x147cd4a 0x146e698 0x2d76df9 0x2d76ad0 0x286ebf5 0x286e962 0x289fbb6 0x289ef44 0x289ee1b 0x2d757e3 0x2d75668 0x146bffc 0x3210 0x3175) libc++abi.dylib: terminate called throwing an exception

第一个断点在:

NSMutableArray *imgArray = [NSMutableArray array];
    IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
    subview.delegate = self;
    subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
    UIImage *img1 = [[UIImage alloc] init];
    img1 = subview.photo.image;
    [imgArray addObject:img1]; //Breaking Here....

不知道这如何突然开始成为一个问题,我已经恢复到早期版本,尝试了另一个工作站,但仍然在下面的代码中看到这个错误:

有任何想法吗?(不得不修剪文件,因此突然结束)

@implementation IMReviewViewController {
    UIScrollView *scrollView;
    //UIPageControl *pageControl;
    BOOL continueButtonDisabled;
    NSUInteger downloadedImageCount;
}

@synthesize frameImage;

@synthesize removeButton;
@synthesize caption;
@synthesize delegate;
@synthesize photo = _photo;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)dealloc
{
    NSLog(@"dealloc - IMReviewViewController");
}

- (void)buttonPressed:(id)sender
{
    //    if (self.delegate && [self.delegate respondsToSelector:@selector(removePhoto:)]) {
    //        [self.delegate removePhoto:removePhoto:self.photo];
    //    }

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

    [self.navigationController popViewControllerAnimated:YES];
}

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetShadow(context, CGSizeMake(3.0f, 3.0f), 2.0f);

    if (self.frameImage) {
        [self.frameImage drawInRect:rect];
    }
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)setReviewImages
{
    continueButtonDisabled = YES;
    downloadedImageCount = 0;

    NSArray *reviewViews = scrollView.subviews;
    for (IMReviewView *reviewView in reviewViews) {
        [reviewView removeFromSuperview];
    }

    NSUInteger photoCount = [[IMLocalUser localUser] cachedPhotoCount];
    if ( nPageNum == 0 ){
        for (NSUInteger i = 0; i < photoCount; i++) {

            CGRect frame;
            frame.origin.x  = scrollView.frame.size.width * i;
            frame.origin.y  = 65;
            frame.size      = CGSizeMake(scrollView.frame.size.width, 327.0f);

            IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
            subview.delegate = self;
            subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:i];
            [scrollView addSubview:subview];

            scrollView.showsHorizontalScrollIndicator = NO;
            scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * i, scrollView.frame.size.height);

            UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
            [self.view addSubview:headingLabel];


            headingLabel.text = @"Time To Preview!";
            headingLabel.textColor = [UIColor blackColor];
            headingLabel.textAlignment = UITextAlignmentCenter;

            headingLabel.textAlignment = NSTextAlignmentCenter;
            headingLabel.tag = 10;
            headingLabel.backgroundColor = [UIColor clearColor];
            headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
            headingLabel.hidden = NO;
            headingLabel.highlighted = YES;
            headingLabel.highlightedTextColor = [UIColor blackColor];
            headingLabel.lineBreakMode = YES;
            headingLabel.numberOfLines = 0;
        }

        //  pageControl.numberOfPages = photoCoun
    }else if( nPageNum == 1 ){

        int nVWidth, nVHeight;
        nVWidth = self.view.frame.size.width;
        nVHeight = (self.view.frame.size.height - 310) / 2;

        CGRect frame;
        frame.origin.x  = 27.0f;
        frame.origin.y  = 65;
        frame.size      = CGSizeMake(269.5f, 253.5f);

        IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
        subview.delegate = self;
        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
        UIImage *img1 = [[UIImage alloc] init];
        img1 = subview.photo.image;

        NSURL *imageURL = [[NSBundle mainBundle] URLForResource:@"FramedBack" withExtension:@"png"];
        frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];

        //Header Text above print

        UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
        [self.view addSubview:headingLabel];


        headingLabel.text = @"Time To Preview!";
        headingLabel.textColor = [UIColor blackColor];
        headingLabel.textAlignment = UITextAlignmentCenter;

        headingLabel.textAlignment = NSTextAlignmentCenter;
        headingLabel.tag = 10;
        headingLabel.backgroundColor = [UIColor clearColor];
        headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
        headingLabel.hidden = NO;
        headingLabel.highlighted = YES;
        headingLabel.highlightedTextColor = [UIColor blackColor];
        headingLabel.lineBreakMode = YES;
        headingLabel.numberOfLines = 0;


        //----------------
        UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
        CGSize divSize = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT);
        UIImage *image = [[UIImage alloc] init];

        image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
        //image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];


        image = img1;
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(300, 300, divSize.width-600, divSize.height-600)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
        [viewImage setFrame:frame];
        [scrollView addSubview:viewImage];

        NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:@"RemoveIcon@2x" withExtension:@"png"];
        UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
        self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
        [self.removeButton setImage:buttonImage forState:UIControlStateNormal];
        [self.removeButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:self.removeButton];


        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
    }else if( nPageNum == 2 ){
        int nVWidth, nVHeight;
        nVWidth = self.view.frame.size.width;
        nVHeight = (self.view.frame.size.height - 330) / 2;

        CGRect frame;
        frame.origin.x  = 27.0f;
        frame.origin.y  = 65;
        frame.size      = CGSizeMake(269.5f, 253.5f);


        NSMutableArray *imgArray = [NSMutableArray array];
        IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
        subview.delegate = self;
        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
        UIImage *img1 = [[UIImage alloc] init];
        img1 = subview.photo.image;
        [imgArray addObject:img1];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
        UIImage *img2 = [[UIImage alloc] init];
        img2 = subview.photo.image;
        [imgArray addObject:img2];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
        UIImage *img3 = [[UIImage alloc] init];
        img3 = subview.photo.image;
        [imgArray addObject:img3];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
        UIImage *img4 = [[UIImage alloc] init];
        img4 = subview.photo.image;
        [imgArray addObject:img4];

        NSURL *imageURL = [[NSBundle mainBundle] URLForResource:@"FramedBack" withExtension:@"png"];
        frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];

        //Header Text above print

        UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
        [self.view addSubview:headingLabel];


        headingLabel.text = @"Time To Preview!";
        headingLabel.textColor = [UIColor blackColor];
        headingLabel.textAlignment = UITextAlignmentCenter;

        headingLabel.textAlignment = NSTextAlignmentCenter;
        headingLabel.tag = 10;
        headingLabel.backgroundColor = [UIColor clearColor];
        headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
        headingLabel.hidden = NO;
        headingLabel.highlighted = YES;
        headingLabel.highlightedTextColor = [UIColor blackColor];
        headingLabel.lineBreakMode = YES;
        headingLabel.numberOfLines = 0;

        //Footer Text under print

        UILabel *footer = [[UILabel alloc] initWithFrame:CGRectMake(50, 330, 226, 50)];
        [self.view addSubview:footer];

        footer.text = @"*Please note, you cannot select the layout of the images within the grid at this time.";
        footer.textColor = [UIColor blackColor];
        footer.textAlignment = UITextAlignmentCenter;

        footer.textAlignment = NSTextAlignmentCenter;
        footer.tag = 10;
        footer.backgroundColor = [UIColor clearColor];
        footer.font = [UIFont systemFontOfSize:9.0f];
        footer.hidden = NO;
        footer.highlighted = YES;
        footer.highlightedTextColor = [UIColor blackColor];
        footer.lineBreakMode = YES;
        footer.numberOfLines = 0;

        //----------------
        UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
        CGSize divSize = CGSizeMake(IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2);
        UIImage *image = [[UIImage alloc] init];

        image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];


        image = [imgArray objectAtIndex:0];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(200, 200, divSize.width-210, divSize.height-210)];

        image = [imgArray objectAtIndex:1];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width, 200, divSize.width-210, divSize.height-210)];

        image = [imgArray objectAtIndex:2];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(200, divSize.height, divSize.width-210, divSize.height-210)];

        image = [imgArray objectAtIndex:3];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width, divSize.height, divSize.width-210, divSize.height-210)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
        [viewImage setFrame:frame];
        [scrollView addSubview:viewImage];

        NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:@"RemoveIcon@2x" withExtension:@"png"];
        UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
        self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
        [self.removeButton setImage:buttonImage forState:UIControlStateNormal];
        [self.removeButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:self.removeButton];


        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
    }else if( nPageNum == 3 ){
        int nVWidth, nVHeight;
        nVWidth = self.view.frame.size.width;
        nVHeight = (self.view.frame.size.height - 243) / 2;
        CGRect frame;
        frame.origin.x  = 27.0f;
        frame.origin.y  = 65;
        frame.size      = CGSizeMake(269.5f, 253.5f);

        NSMutableArray *imgArray = [NSMutableArray array];
        IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
        subview.delegate = self;
        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
        UIImage *img1 = [[UIImage alloc] init];
        img1 = subview.photo.image;
        [imgArray addObject:img1];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
        UIImage *img2 = [[UIImage alloc] init];
        img2 = subview.photo.image;
        [imgArray addObject:img2];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
        UIImage *img3 = [[UIImage alloc] init];
        img3 = subview.photo.image;
        [imgArray addObject:img3];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
        UIImage *img4 = [[UIImage alloc] init];
        img4 = subview.photo.image;
        [imgArray addObject:img4];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:4];
        UIImage *img5 = [[UIImage alloc] init];
        img5 = subview.photo.image;
        [imgArray addObject:img5];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:5];
        UIImage *img6 = [[UIImage alloc] init];
        img6 = subview.photo.image;
        [imgArray addObject:img6];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:6];
        UIImage *img7 = [[UIImage alloc] init];
        img7 = subview.photo.image;
        [imgArray addObject:img7];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:7];
        UIImage *img8 = [[UIImage alloc] init];
        img8 = subview.photo.image;
        [imgArray addObject:img8];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:8];
        UIImage *img9 = [[UIImage alloc] init];
        img9 = subview.photo.image;
        [imgArray addObject:img9];

        NSURL *imageURL = [[NSBundle mainBundle] URLForResource:@"FramedBack" withExtension:@"png"];
        frameImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];

        //Header Text above print

        UILabel *headingLabel = [[UILabel alloc] initWithFrame:CGRectMake(12, 20, 300, 30)];
        [self.view addSubview:headingLabel];


        headingLabel.text = @"Time To Preview!";
        headingLabel.textColor = [UIColor blackColor];
        headingLabel.textAlignment = UITextAlignmentCenter;

        headingLabel.textAlignment = NSTextAlignmentCenter;
        headingLabel.tag = 10;
        headingLabel.backgroundColor = [UIColor clearColor];
        headingLabel.font = [UIFont boldSystemFontOfSize:26.0f];
        headingLabel.hidden = NO;
        headingLabel.highlighted = YES;
        headingLabel.highlightedTextColor = [UIColor blackColor];
        headingLabel.lineBreakMode = YES;
        headingLabel.numberOfLines = 0;

        //Footer Text under print

        UILabel *footer = [[UILabel alloc] initWithFrame:CGRectMake(50, 330, 226, 50)];
        [self.view addSubview:footer];

        footer.text = @"*Please note, you cannot select the layout of the images within the grid at this time.";
        footer.textColor = [UIColor blackColor];
        footer.textAlignment = UITextAlignmentCenter;

        footer.textAlignment = NSTextAlignmentCenter;
        footer.tag = 10;
        footer.backgroundColor = [UIColor clearColor];
        footer.font = [UIFont systemFontOfSize:9.0f];
        footer.hidden = NO;
        footer.highlighted = YES;
        footer.highlightedTextColor = [UIColor blackColor];
        footer.lineBreakMode = YES;
        footer.numberOfLines = 0;

        //----------------
        UIGraphicsBeginImageContext(CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT));
        CGSize divSize = CGSizeMake(IMAGE_WIDTH / 3, IMAGE_HEIGHT / 3);
        UIImage *image = [[UIImage alloc] init];

        image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageURL]];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)];


        image = [imgArray objectAtIndex:0];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(210, 210, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:1];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width + 70, 210, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:2];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width * 2 - 70, 210, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:3];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(210, divSize.height + 70, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:4];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width + 70, divSize.height + 70, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:5];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width * 2 - 70, divSize.height + 70, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:6];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(210, divSize.height*2 -70, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:7];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width + 70, divSize.height*2 -70, divSize.width-150, divSize.height-150)];

        image = [imgArray objectAtIndex:8];
        image = [image resizedImage:divSize interpolationQuality:kCGInterpolationDefault];
        [image drawInRect:CGRectMake(divSize.width * 2 - 70, divSize.height*2 -70, divSize.width-150, divSize.height-150)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();

        UIImageView *viewImage = [[UIImageView alloc] initWithImage:newImage];
        [viewImage setFrame:frame];
        [scrollView addSubview:viewImage];

        NSURL *buottonImageURL = [[NSBundle mainBundle] URLForResource:@"RemoveIcon@2x" withExtension:@"png"];
        UIImage *buttonImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:buottonImageURL]];
        self.removeButton = [[UIButton alloc] initWithFrame:CGRectMake(13.0f, 50, 38.0f, 38.0f)];
        [self.removeButton setImage:buttonImage forState:UIControlStateNormal];
        [self.removeButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [scrollView addSubview:self.removeButton];


        scrollView.showsHorizontalScrollIndicator = NO;
        scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, scrollView.frame.size.height);
    }else if( nPageNum == 4 ){
        int nVWidth, nVHeight;
        nVWidth = self.view.frame.size.width;
        nVHeight = (self.view.frame.size.height - 243) / 2;
        CGRect frame;
        frame.origin.x  = 27.0f;
        //        frame.origin.y  = 23.0f;
        frame.origin.y = 65;
        frame.size      = CGSizeMake(269.5f, 253.5f);

        NSMutableArray *imgArray = [NSMutableArray array];
        IMReviewView *subview = [[IMReviewView alloc] initWithFrame:frame];
        subview.delegate = self;
        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:0];
        UIImage *img1 = [[UIImage alloc] init];
        img1 = subview.photo.image;
        [imgArray addObject:img1];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:1];
        UIImage *img2 = [[UIImage alloc] init];
        img2 = subview.photo.image;
        [imgArray addObject:img2];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:2];
        UIImage *img3 = [[UIImage alloc] init];
        img3 = subview.photo.image;
        [imgArray addObject:img3];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:3];
        UIImage *img4 = [[UIImage alloc] init];
        img4 = subview.photo.image;
        [imgArray addObject:img4];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:4];
        UIImage *img5 = [[UIImage alloc] init];
        img5 = subview.photo.image;
        [imgArray addObject:img5];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:5];
        UIImage *img6 = [[UIImage alloc] init];
        img6 = subview.photo.image;
        [imgArray addObject:img6];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:6];
        UIImage *img7 = [[UIImage alloc] init];
        img7 = subview.photo.image;
        [imgArray addObject:img7];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:7];
        UIImage *img8 = [[UIImage alloc] init];
        img8 = subview.photo.image;
        [imgArray addObject:img8];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:8];
        UIImage *img9 = [[UIImage alloc] init];
        img9 = subview.photo.image;
        [imgArray addObject:img9];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:9];
        UIImage *img10 = [[UIImage alloc] init];
        img10 = subview.photo.image;
        [imgArray addObject:img10];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:10];
        UIImage *img11 = [[UIImage alloc] init];
        img11 = subview.photo.image;
        [imgArray addObject:img11];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:11];
        UIImage *img12 = [[UIImage alloc] init];
        img12 = subview.photo.image;
        [imgArray addObject:img12];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:12];
        UIImage *img13 = [[UIImage alloc] init];
        img13 = subview.photo.image;
        [imgArray addObject:img13];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:13];
        UIImage *img14 = [[UIImage alloc] init];
        img14 = subview.photo.image;
        [imgArray addObject:img14];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:14];
        UIImage *img15 = [[UIImage alloc] init];
        img15 = subview.photo.image;
        [imgArray addObject:img15];

        subview.photo = [[IMLocalUser localUser] cachedPhotoAtIndex:15];
        UIImage *img16 = [[UIImage alloc] init];
        img16 = subview.photo.image;
        [imgArray addObject:img16];
4

1 回答 1

2

由于错误在线:

[imgArray addObject:img1];

这意味着img1nil。既然你从中得到img1意味着subview.photo.image三件事之一:

  1. subview.photo.imagenil
  2. subview.photonil
  3. subviewnil

由于您刚刚创建subview,因此它可能不是#3。因为你subview.photo从:

[[IMLocalUser localUser] cachedPhotoAtIndex:0];

您应该验证这是否返回一个非零值。如果它是非零,则验证该image属性不是nil

边注:

这两行:

UIImage *img1 = [[UIImage alloc] init];
img1 = subview.photo.image;

造成浪费UIImage。做就是了:

UIImage *img1 = subview.photo.image;
于 2013-06-16T01:32:07.387 回答