Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 将URL加载到UIImageView时代码未按预期执行_Iphone_Objective C - Fatal编程技术网

Iphone 将URL加载到UIImageView时代码未按预期执行

Iphone 将URL加载到UIImageView时代码未按预期执行,iphone,objective-c,Iphone,Objective C,我的代码有问题,似乎从来没有正确执行过 我试过很多东西,包括UIActivity、滑块、UIExtViewer等等。。。但它永远不会改变 代码使用xCode中基于导航的应用程序运行。LoadingView是一个文本视图 问题是,看看LoadingView在哪里,它永远不会工作,它总是挂起,用户按下按钮,然后执行此代码。LoadingView是一个文本视图,表示加载的alpha值为0.4,因此基本上,当从网站下载图像时,人们知道它的加载 我也尝试过观点,但都是相同的问题 我怎样才能进步 loadi

我的代码有问题,似乎从来没有正确执行过

我试过很多东西,包括UIActivity、滑块、UIExtViewer等等。。。但它永远不会改变

代码使用xCode中基于导航的应用程序运行。LoadingView是一个文本视图

问题是,看看LoadingView在哪里,它永远不会工作,它总是挂起,用户按下按钮,然后执行此代码。LoadingView是一个文本视图,表示加载的alpha值为0.4,因此基本上,当从网站下载图像时,人们知道它的加载

我也尝试过观点,但都是相同的问题

我怎样才能进步

loadingTview.hidden = false;
today = [NSDate date];
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"dd-MM-yyyy"];
dateString = [dateFormat stringFromDate:today];


if (PageEntered == @"page1")
{
    NSString *url = [NSString stringWithFormat:@"http://www.imagegoeshere.com/%@.jpg",dateString];  
    imageURL = [NSURL URLWithString:url];
    imageData = [NSData dataWithContentsOfURL:url];
    image = [UIImage imageWithData:imageData];
    FullScreenImage.image = image;
    loadingTview.hidden = true;
    [navigationController pushViewController:vFullscreen animated:YES];
}

我不太明白你的问题,但我确实看到了一些几乎肯定是错的。这一行:

if (PageEntered == @"page1")
应该是这样的:

if ([PageEntered isEqualToString:@"page1"])

Objective-C不执行运算符重载,因此您的代码执行的是指针比较,而不是值比较。

我不完全确定问题出在哪里,但我假设当您从view2转到view3时,它会在view2上“挂起”,直到加载图像,然后实际打开view3以显示加载屏幕,对吗

如果是这种情况,那么您要做的是将图像加载到另一个线程中,以便加载不会阻止view3显示加载屏幕

尽管有更干净/更好的方法可以做到这一点,但请看一看

基本上在view3的控制器中执行此操作:

- (void) viewDidLoad { 
    // <First, show your 'Loading...' screen here>
    // Then create a thread to load the image:
    [NSThread detachNewThreadSelector:@selector(loadImage) toTarget:self withObject:nil];   
}

// Then somewhere in the same class define the loading method:
- (void)loadImage {
    // Remember to create a new autorelease pool for this thread.
    // <Load your image here>

    // When image is done loading, call the main thread
    [self performSelectorOnMainThread:@selector(imageDoneLoading) withObject:nil waitUntilDone:YES];
}

// Then define the method to call when the image is done
- (void) imageDoneLoading {
    // Hide the 'Loading...' screen.
}
如果这不是您的问题,那么请提供更多关于实际发生的情况以及问题所在的详细信息


祝你好运。

谢谢你,我现在就开始换。好的,我再解释一下我的问题。我有一个应用程序,它使用导航控制器。我有3个视图控制器。View1 View2 View3让我们这样说。当用户单击View1上的按钮时,它会转到view2,然后当用户单击view2上的按钮时,它会转到view3,它有一个UIImageViewer,可以从Internet加载数据、大图像文件。我想要的是,当用户点击view2上的按钮时,图像下载时会显示一个加载页面,然后一旦下载,删除加载图像,并显示view3。太棒了!这正是问题所在:今晚我将阅读有关NSThread的文档!