1
我是iPhone应用程序和目标c的新手,我无法弄清楚我的方法出了什么问题,总体思路是它包含一个包含纬度和经度的plist,用户输入到文本字段中的数组中存储的数据,然后在该位置输出一个引脚。任何建议将不胜感激。我只发布了该方法的代码,但如果应用程序的其他部分有助于调试我的代码,那么我很乐意发布它。我需要帮助在我的iPhone应用程序中调试方法
-(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];
}
感谢您的帮助
感谢joseph,我修复了其中一个问题,我也在发布其他一些对象。最后一个问题是,当我取消注释这一行:// [currentBus setName:[[dictionary objectForKey:txtFieldData] objectAtIndex:2]];我得到一个未捕获的异常。任何想法为什么? – bubster 2010-10-22 04:57:39
也许索引2没有任何内容? – 2010-10-22 07:30:28