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.