01.
import
"sample.h"
02.
03.
@interface
sample ()
04.
{
05.
NSMutableArray
*myObject;
06.
07.
08.
NSDictionary
*dict;
09.
10.
11.
NSString
*memberid;
12.
NSString
*name;
13.
NSString
*tel;
14.
15.
UIAlertView
*loading;
16.
}
17.
@end
18.
19.
@implementation
sample
20.
21.
@synthesize
receivedData;
22.
23.
- (
id
)initWithNibName:(
NSString
*)nibNameOrNil bundle:(
NSBundle
*)nibBundleOrNil
24.
{
25.
self
= [
super
initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
26.
if
(
self
) {
27.
28.
}
29.
return
self
;
30.
}
31.
32.
- (
void
)viewDidLoad
33.
{
34.
[
super
viewDidLoad];
35.
36.
37.
NSMutableString
*post = [
NSString
stringWithFormat:@
"Name=%@&lastname=%@&Tel=%@&Description=%@"
,_txtName,_txtLastname,_txtphone,_txtdesc];
38.
NSData
*postData = [post dataUsingEncoding:
NSASCIIStringEncoding
allowLossyConversion:
YES
];
39.
NSString
*postLength = [
NSString
stringWithFormat:@
"%d"
, [postData length]];
40.
42.
NSMutableURLRequest
*request = [
NSMutableURLRequest
requestWithURL:url
43.
cachePolicy:
NSURLRequestReloadIgnoringLocalCacheData
44.
timeoutInterval:10.0];
45.
[request setHTTPMethod:@
"POST"
];
46.
[request setValue:postLength forHTTPHeaderField:@
"Content-Length"
];
47.
[request setValue:@
"application/x-www-form-urlencoded"
forHTTPHeaderField:@
"Content-Type"
];
48.
[request setHTTPBody:postData];
49.
50.
NSURLConnection
*theConnection=[[
NSURLConnection
alloc] initWithRequest:request delegate:
self
];
51.
52.
53.
[
UIApplication
sharedApplication].networkActivityIndicatorVisible =
YES
;
54.
55.
loading = [[
UIAlertView
alloc] initWithTitle:@
""
message:@
"Please Wait..."
delegate:
nil
cancelButtonTitle:
nil
otherButtonTitles:
nil
];
56.
UIActivityIndicatorView
*progress= [[
UIActivityIndicatorView
alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
57.
progress.activityIndicatorViewStyle =
UIActivityIndicatorViewStyleWhiteLarge
;
58.
[loading addSubview:progress];
59.
[progress startAnimating];
60.
[progress release];
61.
[loading show];
62.
63.
if
(theConnection) {
64.
self
.receivedData = [[
NSMutableData
data]
retain
];
65.
}
else
{
66.
UIAlertView
*connectFailMessage = [[
UIAlertView
alloc] initWithTitle:@
"NSURLConnection "
message:@
"Failed in viewDidLoad"
delegate:
self
cancelButtonTitle:@
"Ok"
otherButtonTitles:
nil
];
67.
[connectFailMessage show];
68.
[connectFailMessage release];
69.
}
70.
71.
[myTable reloadData];
72.
73.
}