[UIImage retain]:发送给解除分配的实例的消息

时间:2016-12-05 08:53:08

标签: ios objective-c iphone xcode uiimage

首先,我是一个新手,当涉及到xcode时,我尝试了从搜索到调试的所有内容,但是,因为我不明白,我无法用似乎很明显的东西解决它大家......我们有一个应用程序,有点过时(4岁)在工作,我们真的只是改变了标志,并将其更改为64位到目前为止,并尝试在我们的iPhone上运行它,一切正常,除了去一个特定的“页面”(可能不是术语)当我们点击其中一个应打开全屏全景图像的元素时,您可以向左和向右滚动,无休止地退出,并从出现的退出按钮退出。 / p>

以下是崩溃后代码似乎突出显示的地方:

    - (UIImageView *)insertImageView {

UIImageView *imageView = [[UIImageView alloc] initWithImage:vr]; 
imageView.frame = CGRectMake(0, 0, (vr.size.height == 640)? vr.size.width/2 : vr.size.width, 320);

[vrContainerView addSubview:imageView];
return imageView;
    }

    - (CGFloat)placeNewVrOnRight:(CGFloat)rightEdge {
UIImageView *imageView = [self insertImageView];
[visibleVrs addObject:imageView]; 

CGRect frame = [imageView frame];
frame.origin.x = rightEdge;
[imageView setFrame:frame];

return CGRectGetMaxX(frame);
    }

    - (CGFloat)placeNewVrOnLeft:(CGFloat)leftEdge {
UIImageView *imageView = [self insertImageView];
[visibleVrs insertObject:imageView atIndex:0];

CGRect frame = [imageView frame];
frame.origin.x = leftEdge - frame.size.width;
[imageView setFrame:frame];

return CGRectGetMinX(frame);
    }

    - (void)tileVrFromMinX:(CGFloat)minimumVisibleX toMaxX:(CGFloat)maximumVisibleX {
if ([visibleVrs count] == 0) {
    [self placeNewVrOnRight:minimumVisibleX];
}

编辑: 根据我的理解,vr从plist文件中定义的图像引用为包含图像字符串的数组(称为vrFull)。

-(void) chargerVR:(id)sender {
[(AppDelegate *)[[UIApplication sharedApplication] delegate] setIndexBackNavBar:1];

bool vrB = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"vrEnabled"];

bool vrOnHold = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"vrOnHold"];


NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"vr"] URLByAppendingPathExtension:@"jpg"];
NSFileHandle * fileHandle = [NSFileHandle fileHandleForReadingFromURL:fileURL error:nil];

NSData * buffer = nil;
buffer = [fileHandle readDataToEndOfFile];


if (buffer != nil) {
    vrOnHold = NO;

    // test de l'expiration
    NSFileManager* fm = [NSFileManager defaultManager];
    NSDictionary* attrs = [fm attributesOfItemAtPath:[fileURL path] error:nil];
    if (attrs != nil) {

        NSTimeInterval secondsBetween = [[NSDate date] timeIntervalSinceDate:((NSDate*)[attrs objectForKey: NSFileModificationDate])];

        int numberOfDays = secondsBetween / 86400;
        if (numberOfDays > 100) {
            vrOnHold = YES;
        }
    }

}
[fileHandle closeFile];



if (vrOnHold) {
    HTTPClient *httpClient = [[HTTPClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://domain/"]];

    NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET"
                                                            path:[NSString stringWithFormat:@"http://domain/image/%@/showrooms?retina=%s", [[NSBundle mainBundle] bundleIdentifier], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2.0)? "1": "0"]
                                                      parameters:nil];
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [httpClient registerHTTPOperationClass:[AFHTTPRequestOperation class]];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSURL *tmpDirURL = [NSURL fileURLWithPath:NSTemporaryDirectory() isDirectory:YES];
        NSURL *fileURL = [[tmpDirURL URLByAppendingPathComponent:@"vr"] URLByAppendingPathExtension:@"jpg"];
        [responseObject writeToURL:fileURL atomically:YES];


        assert([[NSFileManager defaultManager] fileExistsAtPath: [fileURL path]]);
        [fileURL setResourceValue: [NSNumber numberWithBool: YES]
                           forKey: NSURLIsExcludedFromBackupKey error: nil];

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];
    [operation start];
}


if (vrB) {
    NSArray *vrs = [NSArray arrayWithArray:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"vrFull"]];
    if ([sender tag] < [vrs count]) {
        panorama *pano360 = [[panorama  alloc] init];
        pano360.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
        pano360.view.autoresizesSubviews = YES;
        [pano360 setImage: (buffer == nil)? [UIImage imageNamed:[vrs objectAtIndex:[sender tag]]] : [[UIImage imageWithData:[NSData dataWithContentsOfFile:[fileURL path]]] retain]];
        pano360.hidesBottomBarWhenPushed = YES;

        NGTabBarController * tabBarController = [(AppDelegate *)[[UIApplication sharedApplication] delegate] tabBarController];
        tabBarController.tabBar.hidden =YES;

        [self.navigationController pushViewController:pano360 animated:YES];
        [pano360 release];
    }
}

0 个答案:

没有答案