- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 1 && indexPath.row == 0) {
NSString *requestString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/directions/xml?origin=%@&destination=%@,OK&sensor=false",startField.text,endField.text];
NSURL *url = [[NSURL alloc] initWithString:requestString];
NSData *tempData =[[NSData alloc] initWithContentsOfURL:url];
NSString *Str = [[NSString alloc] initWithData:tempData encoding:NSUTF8StringEncoding];
NSLog(@"%@",Str);
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
xml1 *parser = [[xml1 alloc] init];
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
BOOL success = [xmlParser parse];
if(success){
NSLog(@"No Errors");
arySteps=[[NSMutableArray alloc]init];
arySteps=[parser.ListofSteps1 mutableCopy];
}
else
NSLog(@"Error Error Error!!!");
controller.arayStep=[[NSMutableArray alloc]init];
controller.arayStep=[parser.ListofSteps1 copy];
controller= [[TableView alloc] initWi开发者_C百科thNibName:@"TableView" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
}
In above code i have parsed XML data. In XML-parser file i have store objects in array that is ListofSteps1. Now i access in root-view controller class which is shown in above code. So in root-view class ListofSteps1 assign value to array of root-view controller. Now i want to assign value of array of root-view controller to next view's array which is also maintain in above code but array of next view is not getting value. What is problem in this code so it not getting value?
There are a couple of things wrong with your code above. You alloc and init a fresh array only to write over it on two separate occasions in your method implementation:
arySteps=[[NSMutableArray alloc]init]; // This line serves absolutely no purpose
arySteps=[parser.ListofSteps1 mutableCopy]; // This line is sufficient on its own
Calling accessor methods on an null pointer will do you absolutely no good. You need to instantiate the object before you attempt to set its properties:
controller= [[TableView alloc] initWithNibName:@"TableView" bundle:nil];
controller.arayStep=[parser.ListofSteps1 copy];
These mistakes are very basic and indicate that you need to work on the fundamentals before you can get too much further. I would suggest that you pick up a good book on Objective-C - for example, Programming in Objective-C by Stephen Kochan - and read it thoroughly. A solid understanding of the core concepts will serve you well going forward.
精彩评论