How to uitextfield value pass one uiviewcontroller to another uiviewcontroller.
How to uitextfield value pass one uiviewcontroller to another uiviewcontroller.
I use this method.
// ViewController.h
Code (Objective-C)
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UITextField *txtName;
IBOutlet UITextField *txtLastname;
IBOutlet UITextField *txtphone;
IBOutlet UITextField *txtdesc;
}
@property(nonatomic,assign) NSMutableData *receivedData;
@property(nonatomic,retain) UITextField *txtName;
@property(nonatomic,retain) UITextField *txtLastname;
@property(nonatomic,retain) UITextField *txtphone;
@property(nonatomic,retain) UITextField *txtdesc;
- (IBAction)btnSearch:(id)sender;
@end
// ViewController.m
Code (Objective-C)
#import "ViewController.h"
#import "sample.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize receivedData;
@synthesize txtphone, txtdesc, txtLastname, txtName;
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)btnSearch:(id)sender{
sample *next = [[sample alloc]init];
next.txtName = txtName.text;
next.txtLastname = txtLastname.text;
next.txtphone = txtphone.text;
next.txtdesc = txtdesc.text;
[self presentViewController:next animated:YES completion:nil];
}
// sample.h
Code (Objective-C)
#import <UIKit/UIKit.h>
@interface sample : UIViewController <UITableViewDataSource,UITableViewDelegate>
{
IBOutlet UITableView *myTable;
}
@property (strong, nonatomic) id txtphone;
@property (strong, nonatomic) id txtdesc;
@property (strong, nonatomic) id txtLastname;
@property (strong, nonatomic) id txtName;
@property(nonatomic,assign) NSMutableData *receivedData;
@end
// sample.m
Code (Objective-C)
import "sample.h"
@interface sample ()
{
NSMutableArray *myObject;
// A dictionary object
NSDictionary *dict;
// Define keys
NSString *memberid;
NSString *name;
NSString *tel;
UIAlertView *loading;
}
@end
@implementation sample
@synthesize receivedData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSMutableString *post = [NSString stringWithFormat:@"Name=%@&lastname=%@&Tel=%@&Description=%@",_txtName,_txtLastname,_txtphone,_txtdesc];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://localhost/api/search.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
// Show Progress Loading...
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
loading = [[UIAlertView alloc] initWithTitle:@"" message:@"Please Wait..." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[loading addSubview:progress];
[progress startAnimating];
[progress release];
[loading show];
if (theConnection) {
self.receivedData = [[NSMutableData data] retain];
} else {
UIAlertView *connectFailMessage = [[UIAlertView alloc] initWithTitle:@"NSURLConnection " message:@"Failed in viewDidLoad" delegate: self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[connectFailMessage show];
[connectFailMessage release];
}
[myTable reloadData];
}
but this is going to exception
2013-07-19 16:59:48.637 search[8306:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil. Or, did you forget to nil-terminate your parameter list?'
*** First throw call stack:
(0x1c97012 0x10d4e7e 0x1c783b8 0x4014 0xbda589 0xbd8652 0xbd989a 0xbd860d 0xbd8785 0xb25a68 0x4619911 0x4618bb3 0x4656cda 0x1c398fd 0x465735c 0x46572d5 0x4541250 0x1c1af3f 0x1c1a96f 0x1c3d734 0x1c3cf44 0x1c3ce1b 0x1bf17e3 0x1bf1668 0x18ffc 0x274d 0x2675)
libc++abi.dylib: terminate called throwing an exception
Tag : Mobile, iOS, iPhone, Objective-C
Date :
2013-07-19 18:32:09
By :
vishwa
View :
1114
Reply :
3
Thanks mr.win now working perfectly
Date :
2013-07-22 11:26:40
By :
vishwa
Date :
2013-07-22 12:44:50
By :
mr.win
Load balance : Server 03