1

私はインターネットを検索しましたが、これについてはまったく結果がありません。私のiOSアプリは、カスタムダイナミックセル()で選択された行のタイトルをuilabelに送信するインデックスパスを備えた単純なナビゲーションコントローラーです。キャッチは、データソースがnsarray(coolarrayと呼ばれる)でxml解析されるmysqlからのものであるということです。エラーは次のビューに移動する直前に発生し、次のようにログに記録されます:キャッチされない例外によるアプリの終了'NSInvalidArgumentException'、理由:'[__NSDictionaryI isEqualToString:]:認識されないセレクターがインスタンス0x8887670に送信されました'。ただし、indexPathrow:0または1、あるいは選択されたもののnslog結果は得られます。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
4

1 に答える 1

0

問題は、配列が辞書オブジェクトのコレクションのように見えることです。セグエしようとしているとき、オブジェクトから辞書を取り出して、それを 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);
    }

}
于 2012-11-03T20:04:29.043 に答える