开发者

I need help debugging a method in my iPhone app

I am new to iPhone apps and objective c and I cannot figure out what is wrong with my method the general idea is that it goes to a plist which contain latitudes and longitudes, takes the data stored in the array that the user enters in a text field, and then outputs a pin at that location. Any suggestions would be greatly appreciated. I have only posted the code for the method, but if having any other part of the application would help in debugging my code then I'd be happy to post it.

-(IBAction) showBus {

[busNum resignFirstResponder];

bus *currentBus = [[bus alloc] init];


NSString *txtFieldData = [[NSString alloc] initWithString: busNum.text];



//get data from plist
NSStrin开发者_Python百科g *myFile = [[NSBundle mainBundle] pathForResource:@"busLocations" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile: myFile];

[myFile release];

[currentBus setLat:[[dictionary objectForKey:txtFieldData] objectAtIndex:0]];
[currentBus setLong:[[dictionary objectForKey:txtFieldData] objectAtIndex:1]];
//[currentBus setName:[[dictionary objectForKey:txtFieldData] objectAtIndex:2]];

[txtFieldData release];
[dictionary release];

int latit = [[currentBus Lat] intValue];
int longit = [[currentBus Long] intValue];
NSLog(@"latitude is %d and longitude is %d",latit,longit);

/*
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
*/

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
region.center.latitude = latit;
region.center.longitude = longit;


region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;

[mapView setRegion:region animated:YES]; 
[mapView setDelegate:self];


DisplayMap *ann = [[DisplayMap alloc] init];

ann.title = @"Bus %@",[currentBus name];
ann.coordinate = region.center; 

[mapView addAnnotation:ann];
//[ann release];



[currentBus release];

}

Thanks for the help


You shouldn't be releasing myFile (you did not allocate it), and you should be releasing ann (you did allocate that).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜