Home > ios > Checking the SecondViewControllers textfield in First view Controller

Checking the SecondViewControllers textfield in First view Controller

February 13Hits:1
Advertisement

please say,how to check the second view controllers textfield is empty or not in first view controller while tapping submit button .if it is empty it should show pop.how should i check that in first view controller.please say how to do this ..

Answers

In SecondViewController :- In textFieldDidEndEditing

[itemDict setObject:[NSString stringWithFormat:@"%@",eventTitleTextField.text] forKey:@"itemTitle"];
[[NSNotificationCenter defaultCenter]postNotificationName:@"callViewController" object:nil userInfo:itemDict ];

In FirstViewController :- ViewDidLoad

 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(callViewController:) name:@"callViewController" object:nil];

Then

-(void)callViewController:(NSNotification *)notification
{
NSString *check=[NSString stringWithFormat:@"%@",[notification.userInfo objectForKey:@"itemTitle"];

}
if ([check isEqualToString:@""]) {

    /// do

}else{
    // do
}

Chandrika please check your code like below

Create NSObject class for global variable.
Then declare
 @property(no atomic,strong) NSString *strTextfieldValue;
 Next synthesis  the string in .m file
 @synthesis strTextfieldValue;

Then create the class method in nsobject class finally iniate the string in that method.

Call or import the NSObject class .h in second view. Controller.

Create the object for the NSObject class and initiate the method.

    globalclass.strTextfieldValue=textfieldName.text;

Then import your SecondViewController.h and also import the NSObject class.h in your FirstViewController.h

Finally check whether the string is nil or not in button action method.

Related Articles

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.609 s.