2010-10-20 63 views
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]; 

} 

感謝您的幫助

回答

2

你不應該釋放MYFILE(你沒有分配它),你應該釋放安(你沒有分配該)。

+0

感謝joseph,我修復了其中一個問題,我也在發佈其他一些對象。最後一個問題是,當我取消註釋這一行:// [currentBus setName:[[dictionary objectForKey:txtFieldData] objectAtIndex:2]];我得到一個未捕獲的異常。任何想法爲什麼? – bubster 2010-10-22 04:57:39

+0

也許索引2沒有任何內容? – 2010-10-22 07:30:28

相關問題