Why prompt on the server side I visited twice (in / / 1 and / / 2) do I want to do a data interactively ask what's the problem
This process is basically
When you click categorybutton when the name and other information to the server
post
In the table and then jump to jump in before CategoryTableView in a json obtained from the server and parse the last show
- (IBAction) categoryButton: (id) sender {
/ / Post submitted
NSString * urlString = @ "http://192.168.1.6:8080/iphone/jsonTest.action";
NSString * bodyString = [NSString stringWithFormat: @ "name =% @ & clsId =% @ & sex =% @", username.text, clsId.text, sex.text];
[AppDelegate.kuaidiParams objectForKey: @ "value"], self.searchBar.text];
NSMutableURLRequest * theRequest = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: urlString]];
[TheRequest setHTTPBody: [bodyString dataUsingEncoding: NSUTF8StringEncoding]];
[TheRequest setHTTPMethod: @ "POST"];
[TheRequest addValue: @ "application / x-www-form-urlencoded" forHTTPHeaderField: @ "Content-Type"];
NSURLResponse * response;
NSError * error;
NSData * resultData = [NSURLConnection sendSynchronousRequest: theRequest returningResponse: & response error: & error] ;/ / 1
NSXMLParser * xmlParser = [[[NSXMLParser alloc] initWithData: resultData] autorelease];
[XmlParser parse];
category = [[CategoryTableViewController alloc]
initWithNibName: @ "CategoryTableViewController" bundle: nil];
Growsoft_itemAppDelegate * delegate = [[UIApplication sharedApplication] delegate];
category.title = @ "Category";
category.myData = [[MyDataSource fetchLibraryInformation] retain];
[Delegate.navController pushViewController: category animated: YES];
}
@ Implementation MyDataSource
+ (NSDictionary *) fetchLibraryInformation {
NSString * urlString = [NSString stringWithFormat: @ "http://192.168.1.6:8080/iphone/jsonTest.action"];
NSURL * url = [NSURL URLWithString: urlString];
NSLog (@ "fetching library data");
NSString * aa = [self fetchJSONValueForURL: url];
NSLog (@ "% @ <- url", aa);
return aa;
}
+ (Id) fetchJSONValueForURL: (NSURL *) url {
NSString * jsonString = [[NSString alloc] initWithContentsOfURL: url
encoding: NSUTF8StringEncoding error: nil] ;/ / 2
id jsonValue = [jsonString JSONValue];
[JsonString release];
NSLog (@ "% @ <- JSONValue", jsonValue);
return jsonValue;
}
@ End
Reply:
Break point with what
Reply:
Access has found a place twice, but I do not know why it is, once can not do, or my approach is wrong
Reply:
fetchLibraryInformation why is this file to create a request? ?
Reply:
Get your program already twice, again obtained by NSMutableURLRequest other again in NSString * jsonString = [[NSString alloc] initWithContentsOfURL: url acquisition.
No comments:
Post a Comment