Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use protocol
    text
    copied!<p>I have two viewControllers</p> <ul> <li>ServiceProvider</li> <li>WorkLocation</li> </ul> <p>In <code>ServiceProvider</code> I have one text field and a pick button. When user click on pick button it will redirect to <code>WorkLocation</code> which has a list of <code>location</code>s. When user select any <code>location</code> and then click on pick button from <code>WorkLocation</code> it will redirect back to <code>ServiceProvider</code> page with <code>locationName</code> and <code>Id</code>. And in <code>ServiceProvider</code> page <code>locationName</code> will be displayed in the text field which is already there.</p> <p>To perform this I am using a protocol.</p> <p>WorkLocation declaration:</p> <pre><code> #import &lt;UIKit/UIKit.h&gt; #import "WorkDetailCell.h" @protocol WorkLocationDetailViewDelegate &lt;NSObject&gt; @required -(void)organizationInfo:(NSString *) organization_id name:(NSString *)name; @end @interface WorkLocationDetailsViewController :UIViewController &lt; UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate &gt; { IBOutlet UITableView *workLocationTableView; IBOutlet UISearchBar *workLocationSearchBar; NSMutableArray *workDetailArray,*tempDataArray,*searchArray,*searchResultArray; BOOL search; } @property (nonatomic,retain) id &lt; WorkLocationDetailViewDelegate &gt; delegate; </code></pre> <p>WorkLocation implementation:</p> <pre><code> -(IBAction)doneButtonClicked:(id)sender { if (search==FALSE) { NSLog(@"pick%d",[sender tag]); NSLog(@"pick from temp"); NSDictionary *detailList=[tempDataArray objectAtIndex:[sender tag]]; [_delegate organizationInfo:detailList[@"organizationId"] name:detailList[@"organizationName"]]; } else { NSLog(@"pick from search"); } [self.navigationController popToRootViewControllerAnimated:YES]; } </code></pre> <p>and in ServiceProvider implementation file:</p> <pre><code>-(void)organizationInfo:(NSString*)organization_id name:(NSString *)name { NSString *id=organization_id; txtWorkLocation.text=name; NSLog(@"%@ %@",organization_id,name); } </code></pre> <p>Now when I came back from <code>WorkLocation</code> page this method is not called. Declaration of <code>ServiceProvider</code>:</p> <pre><code>#import "WorkLocationDetailsViewController.h" @class RadioButtonView; @class WorkLocationDetailsViewController; @protocol ServiceProviderProfileDelegate &lt;NSObject&gt; @required -(void)setProImages:(UIImage *)img; @end @interface ServiceProviderProfileViewController : UIViewController &lt; UINavigationControllerDelegate, UIImagePickerControllerDelegate, RadioButtonDelegate, WorkLocationDetailViewDelegate &gt; { NSString *gratuityStr,*paymentStr; RadioButtonView *gratuityGroup,*paymentGroup; IBOutlet UILabel *usernameLabel; NSString *gratuitySelection,*receivePayment; WorkLocationDetailsViewController *WorkVC; } </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