2010-06-18 29 views
0

我的代码有问题,它似乎永远不会正确执行。将URL加载到UIImageView中时,代码没有按预期执行

我试着从UIActivity,滑块,UITextVieweer等等很多东西......但它永远不会改变,

的代码是用在Xcode基于导航的应用程序运行。 loadingTview是一个TextView,

的问题是,看到loadingTview是,永远不会奏效,它总是挂,用户按下一个按钮,执行该代码。 loadingTview是一个文本视图,用于在页面下载图像时使用0.4的alpha值进行“加载”,人们知道它的加载。

我试过的意见很好,但同样的问题。

我怎么能进步呢?

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]; 
} 

回答

0

我不知道完全的问题是什么,但我认为,当你从视图2去,直到图像实际上是打开VIEW3显示加载屏幕,右侧前加载到VIEW3它“挂起”的视图2?

如果是这样的话,那么你需要做的是加载图像在不同的线程使加载不会显示加载屏幕挡住VIEW3。

看一看NSThread(虽然有清洁剂/更好的方法来做到这一点)。

基本上做到这一点在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. 
} 

如果这不是你有问题,那么请提供更多的细节,什么是真正发生什么问题。

祝你好运。

+0

太棒了!那正是问题所在:)我今天晚上阅读了NSThread的文档! – user370507 2010-06-18 20:30:30

0

我真的不明白你的问题,但我确实看到了几乎肯定是错的东西。这条线:

if (PageEntered == @"page1") 

应该是这样的:

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

的Objective-C没有做运算符重载,所以你的代码做一个指针的比较,而不是一个值比较。

+0

谢谢你,生病得到改变,现在。 好吧,虐待解释更多关于我的问题。 我有一个应用程序,它使用导航控制器。我有3个视图控制器。 View1 View2 View3可以说。当用户单击View1上的按钮时,它将转到view2,然后当用户单击view2上的按钮时,它会转到view3,它具有一个UIImageViewer,它从Internet上加载数据,大图像文件。我想要的是,当用户在view2上舔按钮时,在下载图像时显示加载页面,然后下载一次,移除该加载图像并显示view3。 – user370507 2010-06-18 18:12:49