Judge the problem when there is no network, and the screen when the network is not prompt.

Source: Internet
Author: User

Learning to write programs in iOS often determines that there is a problem that crashes when there is no network.

Initializing data

-(void) _loaddata

{

//Send network request

< Span style= "COLOR: #000000" >    [ wxdataservice requestafwithurl : @ "Fill request URL" params : nil requestheader : nil HttpMethod : @ "Get or fill post" block :^ ( nsobject *result) {

//I will crash when I'm out of the net.

if ([Result iskindofclass: [nserror class]]) {

return [selfinternetfail];// can call a method that shows the screen when it is not on the network.

}

NSLog (@ "result:%@", result);

//Create variable array to hold models

nsmutablearray *models=[[nsmutablearrayalloc]init];

nsdictionary *results = (nsdictionary *) result;

nsarray *datas = results[@ "Datas"];

for (nsdictionary *dic in Datas) {

nsarray *infos = dic[@ "Infos"];

for (nsdictionary *subdic in Infos) {

NSLog (@ "infos=%@", infos);

Ticketmodel *model=[[ticketmodelalloc]initwithcontentsofdic: Subdic];

[Models AddObject: Model];

}

Self. dataList = models;

[_tableview reloaddata];//reload Refresh table view.

}

}];

}


/*

Prompt when no network

such as loading such a screen

*/


Network Load Failure Popup interface call

-(void) Internetfail

{

uiimageview *imageview=[[uiimageviewalloc]initwithframe:cgrectmake (a);

ImageView. Image =[UIImageimagenamed:@ "[email protected]"];

[Self. View addsubview: ImageView];

UILabel *label=[[UILabelalloc]init];

Label. frame=cgrectmake(kscreenwidth,max, +--) ;

Label. text=@ "Pro, message failed to load";

label. Font =[uifontboldsystemfontofsize:];

[Self. View addsubview: label];

UILabel *label1=[[UILabelalloc]init];

Label1. frame=cgrectmake(+, +,kscreenwidth-+);

Label1. text =@ "Please check your phone network settings and click Reload";

Label1. Font =[uifontboldsystemfontofsize:];

Label1. numberoflines=0;

[Self. View addsubview: Label1];

}


Judge the problem when there is no network, and the screen when the network is not prompt.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.