Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom delegation to pass data between tab bar view in iOS not working
    primarykey
    data
    text
    <p>I am facing a problem related to delegation.I have 2 tabView. In first tabview i have 2 textfield and a button(to trigger the delegate method) and in the second tabview i have 2 label to display the content of textfield in the first tabview.Whats wrong with my code???</p> <p>For first tabviewA the .h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class ViewControllerA; @protocol ViewControllerADelegate &lt;NSObject&gt; -(void)sayHello:(ViewControllerA*)viewController; @end @interface ViewControllerA : UIViewController&lt;UITextFieldDelegate&gt; @property (nonatomic,strong)IBOutlet UITextField *textFieldFirst; @property (nonatomic,strong)IBOutlet UITextField *textFieldSecond; @property (nonatomic,strong)id&lt;ViewControllerADelegate&gt;delegate; -(IBAction)next:(id)sender; @end </code></pre> <p>and the .m file </p> <pre><code>#import "ViewControllerA.h" @interface ViewControllerA () @end @implementation ViewControllerA @synthesize textFieldFirst=_textFieldFirst; @synthesize textFieldSecond=_textFieldSecond; @synthesize delegate=_delegate; - (void)viewDidLoad { [super viewDidLoad]; _textFieldFirst.delegate=self; _textFieldSecond.delegate=self; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField resignFirstResponder]; return NO; } -(IBAction)next:(id)sender { [self.delegate sayHello:self]; } @end </code></pre> <p>And for the second tabbarViewB the .h file</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "ViewControllerA.h" @interface ViewControllerB : UIViewController&lt;ViewControllerADelegate&gt; @property (nonatomic,strong)IBOutlet UILabel *labelFirst; @property (nonatomic,strong)IBOutlet UILabel *labelSecond; @end </code></pre> <p>and the .m file</p> <pre><code>#import "ViewControllerB.h" @interface ViewControllerB () @end @implementation ViewControllerB @synthesize labelFirst=_labelFirst; @synthesize labelSecond=_labelSecond; - (void)viewDidLoad { [super viewDidLoad]; ViewControllerA *viewControllerA=[self.tabBarController.viewControllers objectAtIndex:0]; viewControllerA.delegate=self; // Do any additional setup after loading the view. } -(void)sayHello:(ViewControllerA *)viewController { _labelFirst.text=viewController.textFieldFirst.text; _labelSecond.text=viewController.textFieldSecond.text; } @end </code></pre> <p>N.B: I have tried tabView B to tabview A with the same process and that worked fine. The reverse (i.e from A to B)is not working at all.Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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