编辑:此问题已移至从 Xcode 获取与索引路径无关的错误,因为此问题已修复但出现新错误。
我已经在这里待了4天!我在日志中没有收到任何错误,但是每当我单击填充有从 mysql 下载的动态数组的单元格时,它都不会转换。有趣的是,我没有从 prepareForSegue 中的自我放置的 nslog 中得到任何回应......
视图控制器.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
@interface ViewController : UIViewController<UITableViewDataSource,
CLLocationManagerDelegate,NSXMLParserDelegate, UISearchBarDelegate> {
IBOutlet UISearchBar *searchBar;
IBOutlet UITableView *tableView;
IBOutlet UILabel *Label;
CLLocationManager *locationManager;
NSMutableArray *coolarray;
float latitude;
float longitude;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
我已经排除了已解析的 xml 下载数据,但将 nsarray 的值留在了我的实现文件中
#import "ViewController.h"
#import "DetailViewController.h"
#import "Player.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];
}
- (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];
UILabel *nameLabel =[cell textLabel];
[nameLabel setText:[itemAtIndex objectForKey:@"name"]];
return cell;
}
- (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];
UILabel *nameLabel =[cell textLabel];
[nameLabel setText:[itemAtIndex objectForKey:@"name"]];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *selectedLang = [coolarray objectAtIndex:indexPath.row];
DetailViewController *myDetViewCont = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
myDetViewCont.myDogLang = selectedLang;
[self performSegueWithIdentifier:@"showDogDetail" sender:nil];
[myDetViewCont release];
myDetViewCont = nil;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDogDetail"])
{
DetailViewController *detailViewController =
[segue destinationViewController];
NSIndexPath *indexPath = [self.tableView
indexPathForSelectedRow];
NSString *dogLang = [self.coolarray objectAtIndex:indexPath.row];
detailViewController.myDogLang = dogLang;
}
}
@end
DetailViewController.h
#import <UIKit/UIKit.h>
@interface DetailViewController : UIViewController
{
IBOutlet UILabel *myLabel;
NSString *myDogLang;
}
@property (nonatomic, retain) IBOutlet UILabel *myLabel;
@property (nonatomic, retain) NSString *myDogLang;
@end
细节视图控制器.m
#import "DetailViewController.h"
@interface DetailViewController ()
@end
@implementation DetailViewController
@synthesize myLabel;
@synthesize myDogLang;
- (void)viewDidLoad {
[super viewDidLoad];
myLabel.text = myDogLang;
self.myLabel.text = [self.myLabel objectAtIndex:0];
}
- (void)dealloc {
[myLabel release];
[myDogLang release];
[super dealloc];
}
我还添加了一张图片来显示我的连接: