Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>Here you can use Custom Delegates in ios.. just create Custom Delegate(Protocol) in AppDelegate or Singleton Class.Here im using AppDelegate #import &lt;UIKit/UIKit.h&gt; **AppDeleagte.h** @protocol parserDelegate &lt;NSObject&gt; -(void)sendDataToCorrespondingViewController:(id)data andServiceName:(NSString *)serviceName; @end @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt; { } @property (strong, nonatomic) UIWindow *window; @property (nonatomic,strong) id &lt;parserDelegate&gt; delegate; -(void)getMethodURL:(NSString *)urlString andServiceName:(NSString *)serviceName; @end **AppDeleagte.m** //Implementing getMethod() in AppDelegate.m File -(void)getMethodURL:(NSString *)urlString andServiceName:(NSString *)serviceName; { NSURL *url =[NSURL URLWithString:urlString]; NSError *error; { dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 2), ^{ NSData *data =[[NSData alloc]initWithContentsOfURL:url]; if (data == nil) { NSLog(@"error bcz data is nil:%@",error.localizedDescription); } else { NSError *error; id response =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&amp;error]; [self.delegate sendDataToCorrespondingViewController:response andServiceName:serviceName]; } }); } } Now import AppDelegate in required ViewController and Create instance For AppDelegate **ViewController.h** #import &lt;UIKit/UIKit.h&gt; #import "AppDelegate.h" @interface ViewController : UIViewController&lt;parserDelegate&gt; { } @property (nonatomic,strong) AppDelegate *appDelegate; @end **ViewController.m** #import "ViewController.h" @interface ViewController () @end @implementation ViewController @synthesize appDelegate; - (void)viewDidLoad { self.appDelegate =(AppDelegate *)[[UIApplication sharedApplication] delegate]; self.appDelegate.delegate=self; [super viewDidLoad]; } -(IBAction)getSeviceData:(id)sender { //call AppDeleagte method for Webservice [self.appDelegate getMethodURL:@"http://www.tranzlogix.com/tranzlogix_webservice/vehiclelist.php?format=json" andServiceName:@"VehicleList"]; } //implement Deleagte method -(void)sendDataToCorrespondingViewController:(id)data andServiceName:(NSString *)serviceName { NSLog(@"response data: %@",data); //Here is the response from websevice NSLog(@"serviceName: %@",serviceName); // Here Service name differentiate,if we call 2 webservices in ViewController } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload