0

編集:この質問は修正されましたが、新しいエラーが表示されたため、インデックスパスに関連するインターネット上にないXcodeからエラーを取得するに移動しました。

私はこれに4日間います!ログにエラーは記録されていませんが、mysql からダウンロードした動的配列が取り込まれたセルをクリックしても、遷移しません。興味深いことに、prepareForSegue に自己配置した nslogs から応答がありませんでした...

ViewController.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

DetailViewController.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];
}

接続を示す写真も追加しました。 ここに画像の説明を入力

4

2 に答える 2

1

ここでは、いくつかの異なるスタイルを組み合わせて一致させているようです...コードを単純化することをお勧めします。

1)テーブルと詳細ビューの間の現在のセグエを削除します。コントロールキーを押しながらプロトタイプセル(これはプロトタイプテーブルであると想定しています)から宛先ビューにドラッグして、新しいセルを作成します。識別子には、prepareForSegueコードで使用しているのと同じ名前を付けることを忘れないでください)。また、ナビゲーションコントローラーにテーブルビューコントローラーが埋め込まれている場合(これは、ナビゲート可能なテーブルビューで通常期待されることです)、セグエのスタイルは「プッシュ」である必要があります。それ以外の場合、スタイルは「モーダル」にする必要があります(ただし、アプリの使いやすさによっては、このアプローチを再検討することをお勧めします)。

ここに画像の説明を入力してください

2)Playerクラスはどうなっていますか?これはUITableViewCellを拡張するクラスですか?ストーリーボードのプロトタイプセルをクリックすると、IDインスペクターにどのクラスが表示されますか?それはPlayerまたはUITableViewCellですか?属性インスペクターのセルの識別子は何ですか?それはプレーヤーですか、それとも空白ですか(コードを指定すると、「プレーヤー」である必要があります)?少なくとも一時的に、Playerクラスを写真から外してみてください。セルの識別子をとして保持しますがPlayer、IDインスペクターで、プロトタイプセルのカスタムクラスをに設定しUITableViewCellます。tableView:cellForRowAtIndexPath:メソッドを次のように変更します。

- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Player"];

    NSDictionary *itemAtIndex = (NSDictionary *)[self.coolarray objectAtIndex:indexPath.row];
    cell.textLabel.text = [itemAtIndex objectForKey:@"name"];
    return cell;
}

また、ここでの補足として、このメソッドでは、coolarrayのメンバーがNSDictionaryタイプであることを示しています。prepareForSegueでは、coolarrayのメンバーをNSStringとして扱います。両方になることはできません。

3)tableView:didSelectRowAtIndexPath:メソッドを削除します。これは重要。ここで起こっているセグエの2つの競合する方法があります。ストーリーボードとこのメソッドで設定されたもの。現在のコードの記述方法では、セルをクリックすると、prepareForSegue->didSelect->prepareForSegueが呼び出されます。ここで実行しようとしていることはすべて、prepareForSegue:メソッドで実行できます(次の手順を参照)。

4)prepareForSegue:メソッドを次のように変更します(現在、セグエが1つしかないため、「if」ステートメントを削除することもできます)。

-(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];
        // or if the array contains NSDictionaries, change the previous line to:
        // NSString *dogLang = [[self.coolarray objectAtIndex:indexPath.row] objectForKey:@"name"];
        detailViewController.myDogLang = dogLang;
    }
}

5)DetailViewControllerのviewDidLoadメソッドが、ラベルテキストを不正なコードでオーバーライドしています(UILabelは配列ではありません)。コードを次のように変更します。

- (void)viewDidLoad {
    [super viewDidLoad];
    self.myLabel.text = self.myDogLang;
}

私が上で述べた概念的な問題のいくつかを考えると、私はアップルのテーブルビュープログラミングガイドを読むことを強くお勧めします。ライフサイクルとフローを明確にするのに役立ちます。

于 2012-11-03T05:02:44.450 に答える
0

1-使用するアプローチを選択する必要があります。ストーリーボード内の接続またはプログラムでロードされた詳細コントローラー(didSelectRowAtIndexPathを使用)によるセグエ。今、あなたは両方のことをやっています: ダメです。すべての didSelectRowAtIndexPath コードにコメントを付けて、ストーリーボードのみを使用してください。さらに、あなたの didSelectRowAtIndexPath では、ペン先から詳細 vc をロードしていますか??? どのニブ?ペン先はありません。絵コンテがあります。(ストーリーボードからプログラムで読み込むこともできますが、コードは異なります)

2- セグエにプッシュを使用する場合は、ストーリーボードに UINavigationController が必要です。nav コントローラーを配置します。ストーリーボードに配置すると、UITableViewController が添付されます。この UITV を取り外して、自分のものを取り付けます。セルを詳細コントローラーに再接続し、接続に識別子名を付けることを忘れないでください。接続がセルから開始されるようにしてください。モーダル セグエでも UINavigationController が必要かどうかはわかりません。

試してみて、私に知らせてください

于 2012-11-03T12:53:02.373 に答える