如何处理从bad url加载xml的冻结programm? [英] How to handle freezing programm at loading xml from bad url?
本文介绍了如何处理从bad url加载xml的冻结programm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想处理冻结我的程序,当它从坏地址加载一个XML。
我尝试使用@try和@catch,但它不工作。
我可以使用一些替代处理吗?
I want to handle freezing my program, when it load an xml from bad address. I tryed it with using @try and @catch, but it doesn't work. Can I use some alternative handling?
@try{
NSString *test=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%@",addressLabel.text,portLabel.text]] encoding:NSUTF8StringEncoding error: nil];
}
@catch (NSException *ex) {
NSLog(@"Bad IP address");
return;
}
推荐答案
code> NSThread ,并在出现错误时使用通知。
Run your XML Parser in NSThread
and use notification for errors.
这篇关于如何处理从bad url加载xml的冻结programm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文