我需要帮助调试我的iPhone应用程序中的方法

时间:2010-10-20 05:40:06

标签: iphone cocoa-touch debugging

我是iPhone应用程序和目标c的新手,我无法弄清楚我的方法有什么问题,一般的想法是它转到包含纬度和经度的plist,获取存储在用户输入的数组中的数据在文本字段中,然后在该位置输出一个引脚。任何建议将不胜感激。我只发布了该方法的代码,但如果该应用程序的任何其他部分有助于调试我的代码,那么我很乐意发布它。

-(IBAction) showBus {

[busNum resignFirstResponder];

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


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



//get data from plist
NSString *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];

}

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

你不应该释放myFile(你没有分配它),你应该释放ann(你确实分配了它)。