从与索引path相关的互联网上的Xcode中获取错误

我搜查了互联网,并没有得到这个结果。 我的ios应用程序只是一个简单的导航控制器与索引path应该发送一个自定义dynamic单元格()选定行的标题到一个uilabel。 问题在于数据源来自mysql,它是在nsarray(称为coolarray)中parsing的xml。 错误发生在移动到下一个视图之前,并在日志中: 终止应用程序,由于未捕获的exception“NSInvalidArgumentException”,原因:'[__NSDictionaryI isEqualToString:]:无法识别的select发送到实例0x8887670'。 但是,它确实给出了indexPathrow的结果:0或1,或者select了什么。 这个数组交给uilabel一定是个问题,但是我弄不明白! 我遗漏了自定义单元的代码,因为这不太可能是错误的原因,工作正常(加上是简单的死亡)。 这是UITableView的一个早期问题的后续拒绝去detailViewController ,但代码不再相关,因为,你可以看到,我的代码已经大大改变。

ViewController.h

#import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h> #import "Player.h" @interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource, CLLocationManagerDelegate,NSXMLParserDelegate, UISearchBarDelegate> { IBOutlet UISearchBar *searchBar; CLLocationManager *locationManager; NSMutableArray *coolarray; float latitude; float longitude; } @property(nonatomic,strong) IBOutlet UITableView * tableView; @property (nonatomic, retain) CLLocationManager *locationManager; @end 

ViewController.m

 #import "ViewController.h" #import "LoadingViewController.h" @interface ViewController () @end @implementation ViewController - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [super dealloc]; [self.locationManager release]; if ( coolarray ) [coolarray release]; } - (void)viewDidLoad { [super viewDidLoad]; coolarray = NULL; self.locationManager = [[[CLLocationManager alloc] init] autorelease]; self.locationManager.delegate = self; [self.locationManager startUpdatingLocation]; [[self navigationController] setNavigationBarHidden:YES]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } // Table data delegate - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { if ( coolarray != NULL ) { return [coolarray count]; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath { Player *cell = [_tableView dequeueReusableCellWithIdentifier:@"Player"]; if (cell == nil) { cell = [[[Player alloc] initWithFrame:CGRectZero reuseIdentifier:@"Player"] autorelease]; } NSDictionary *itemAtIndex =(NSDictionary *)[coolarray objectAtIndex:indexPath.row]; cell.nameLabel.text = [itemAtIndex objectForKey:@"name"]; return cell; } // XML request and parsing - (void)updateLocation:(CLLocation *)newLocation { if ( coolarray ) { [coolarray release]; } coolarray = [[NSMutableArray alloc] init]; if ( newLocation ) { latitude = newLocation.coordinate.latitude; longitude = newLocation.coordinate.longitude; } NSString *urlString = [NSString stringWithFormat:@"(censored)"]; NSXMLParser *locationParser = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease]; [locationParser setDelegate:self]; [locationParser parse]; [_tableView reloadData]; } - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if ( [elementName isEqualToString:@"location"]) { [coolarray addObject:[[NSDictionary alloc] initWithDictionary:attributeDict]]; } } // GPS handling - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [self updateLocation:newLocation]; } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { } // Search bar handling - (void)searchBarSearchButtonClicked:(UISearchBar *)sb { [self updateLocation:NULL]; [searchBar resignFirstResponder]; } - (void)searchBarCancelButtonClicked:(UISearchBar *)sb { [searchBar resignFirstResponder]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"showDetail"]) { NSIndexPath * indexPath=[self->_tableView indexPathForSelectedRow]; LoadingViewController* destViewController= segue.destinationViewController; destViewController.myProgLang=[coolarray objectAtIndex:indexPath.row]; NSLog(@"indexPathrow:%d",indexPath.row); } } @end 

LoadingViewController.h(我的详细信息视图)

 #import <UIKit/UIKit.h> @interface LoadingViewController : UIViewController { } @property (nonatomic, retain) IBOutlet UILabel *myLabel; @property (nonatomic, retain) NSString *myProgLang; @end 

LoadingViewController.m(我的详细信息视图)

 #import "LoadingViewController.h" @interface LoadingViewController () @end @implementation LoadingViewController @synthesize myLabel, myProgLang; - (void)viewDidLoad { [super viewDidLoad]; myLabel.text = myProgLang; [[self navigationController] setNavigationBarHidden:YES]; } - (void)dealloc { [myLabel release]; [myProgLang release]; [super dealloc]; } @end 

问题是你的数组看起来是一个字典对象的集合。 当你要继续时,你正在从对象中取出一个字典,并试图把它作为一个NSString属性来存储。

尝试改变你的prepareForSegue:方法如下:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if([segue.identifier isEqualToString:@"showDetail"]) { NSIndexPath * indexPath=[self->_tableView indexPathForSelectedRow]; LoadingViewController* destViewController= segue.destinationViewController; destViewController.myProgLang=[[coolarray objectAtIndex:indexPath.row] objectForKey:@"name"]; NSLog(@"indexPathrow:%d",indexPath.row); } }