0

Apple 開発者プログラムから「Your Second iOS App」チュートリアルを完了しようとしています。基本的なtableViewアプリです。私の問題は、アプリが警告なしで正常にビルドされていることですが、詳細ビューをマスター ビューから切り離すことができません。セグエ識別子とアップルが提供したコードの両方をコピーして貼り付けました。セグエはプッシュを使用しており、それを削除して数回再試行しました。シミュレーターでアプリをテストしています。

  1. セグエが機能しているかどうかを確認するにはどうすればよいですか?

  2. コードを Xcode からコピーしてスタック オーバーフローの質問テキスト領域に貼り付けるたびに、下部にコードを 4 つのスペースでインデントする必要があるという警告が表示されます。これは、行ごとにコードをインデントする必要があるということですか?? コントロール + k を実行して強調表示された領域に貼り付けましたが、それでも警告が表示されますか??

  3. シミュレーターを実行して見ているときに、開示インジケーターをクリックして使用しようとしていますが、control = click または command = click などの特別なものをプッシュする必要がありますか?

BirdsMasterViewController.m ファイルのコードは次のとおりです。

            //
            //  BirdsMasterViewController.m
            //  BirdWatching
            //
            //  Created by David Hall on 11/13/12.
            //  Copyright (c) 2012 David Hall. All rights reserved.
            //

            #import "BirdsMasterViewController.h"

            #import "BirdsDetailViewController.h"

            #import "BirdSightingDataController.h"

            #import "BirdSighting.h"

            /*
            @interface BirdsMasterViewController () {
                NSMutableArray *_objects;
            }
            @end
            */
            @implementation BirdsMasterViewController

            - (void)awakeFromNib
            {
                [super awakeFromNib];

                self.dataController = [[BirdSightingDataController alloc] init];
            }

            - (void)viewDidLoad
            {
                [super viewDidLoad];
                // Do any additional setup after loading the view, typically from a nib.
            /*
                self.navigationItem.leftBarButtonItem = self.editButtonItem;

                UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
                self.navigationItem.rightBarButtonItem = addButton;
            */
             }

            - (void)viewDidUnload
            {
                [super viewDidUnload];
                // Release any retained subviews of the main view.
            }

            - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
            {
                return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
            }

            /*- (void)insertNewObject:(id)sender
            {
                if (!_objects) {
                    _objects = [[NSMutableArray alloc] init];
                }
                [_objects insertObject:[NSDate date] atIndex:0];
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
            }
            */
            #pragma mark - Table View

            - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
            {
                return 1;
            }

            - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
            {
                return [self.dataController countOfList];
            }

            - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
            {
                static NSString *CellIdentifier = @"BirdSightingCell";

                static NSDateFormatter *formatter = nil;
                if (formatter == nil)
                {
                    formatter = [[NSDateFormatter alloc] init];
                    [formatter setDateStyle:NSDateFormatterMediumStyle];
                }

                UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
                [[cell textLabel] setText:sightingAtIndex.name];
                [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];


                return cell;
            }

            - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
            {
                // Return NO if you do not want the specified item to be editable.
                return NO;
            }

            /*- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
            {
                if (editingStyle == UITableViewCellEditingStyleDelete) {
                    [_objects removeObjectAtIndex:indexPath.row];
                    [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
                } else if (editingStyle == UITableViewCellEditingStyleInsert) {
                    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
                }
            }
            */
            /*
            // Override to support rearranging the table view.
            - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
            {
            }
            */

            /*
            // Override to support conditional rearranging of the table view.
            - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
            {
                // Return NO if you do not want the item to be re-orderable.
                return YES;
            }
            */

            - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
            {
                if ([[segue identifier] isEqualToString:@"ShowSightingDetails"]) {
                    BirdsDetailViewController *detailViewController = [segue destinationViewController];
                    detailViewController.sighting = [self.dataController objectInListAtIndex:[self.tableView indexPathForSelectedRow].row];

                }
            }

            @end

BirdsDetailViewController.m のコードは次のとおりです。

        //
        //  BirdSightingDataController.m
        //  BirdWatching
        //
        //  Created by David Hall on 11/25/12.
        //  Copyright (c) 2012 David Hall. All rights reserved.
        //

        #import "BirdSightingDataController.h"
        #import "BirdSighting.h"

        @interface BirdSightingDataController ()

        - (void)initializeDefaultDataList;

        @end

        @implementation BirdSightingDataController

        - (void)initializeDefaultDataList
        {
            NSMutableArray *sightingList = [[NSMutableArray alloc] init];

            self.masterBirdSightingList = sightingList;

            BirdSighting *sighting;

            NSDate *today = [NSDate date];

            sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere" date:today];

            [self addBirdSightingWithSighting:sighting];

        }

        - (void)setMasterBirdSightingList:(NSMutableArray *)newList
        {
            if (_masterBirdSightingList != newList)
            {
                _masterBirdSightingList = [newList mutableCopy];
            }

        }

        - (id)init
        {
            if (self = [super init])
            {
                [self initializeDefaultDataList];

                return self;
            }

            return nil;
        }

        - (NSUInteger)countOfList
        {
            return [self.masterBirdSightingList count];
        }

        - (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex
        {
            return [self.masterBirdSightingList objectAtIndex:theIndex];
        }

        - (void)addBirdSightingWithSighting:(BirdSighting *)sighting
        {
            [self.masterBirdSightingList addObject:sighting];
        }









        @end

デビッド・ホール

4

3 に答える 3

0
  1. それが機能するとき、それは機能しています。しかし、あなたが何をしているのかをもっと知らなければ、答えを出すのは難しいです。

  2. テキストボックスでコードを強調表示してから、このボタンをクリックします。

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

    コードが正しくインデントされます。

  3. この質問を理解することはできません。

追加するために編集

(OPが私に郵送したプロジェクトのコピーを見た後)

あなたのセグエは正しく配線されていませんでした。

ポイントはセルのクリックで遷移することであるため、セグエはセルから次のビューコントローラに移動することになっています。セグエはコントローラーから詳細ビューコントローラーに接続されています。プロジェクトで-ViewControllerを右クリックすると、セグエが手動で接続されていることがわかります。ただし、セルを右クリックしても、セグエ接続は表示されません。

現在のセグエを削除して再作成します。今回は、セルから次のViewControllerにcontrolキーを押しながらドラッグします。次に、セルを右クリックしてセグエが接続されていることを確認することにより、接続を再確認できます。

次のようになります。

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

于 2012-11-29T14:55:15.267 に答える
0

1.と2に関するCalebとAbizemからの他の回答を参照してください。あなたの質問No.3を正しく理解した場合、答えはNoです。テーブル行または詳細開示インジケーターを選択する場合は、シミュレーターで特に何かを押す必要はありません。デバイスでタップするアイテムをクリックするだけです。セグエが発生しない場合は、シミュレータが問題を引き起こしていない可能性があります:)

于 2012-11-29T15:27:01.810 に答える
0
  1. セグエがテーブルから詳細ビューに遷移するはずで、テーブルから詳細ビューに移動できない場合、セグエは機能していません。

  2. SO エディターの上部にあるコード サンプル ボタンを使用するか、テキスト エディターでコードを選択してインデントしてからコピーすることができます。たとえば、Xcode では、コードを選択し、Command-] を押してコピーするのは簡単です。次に、SO エディターに貼り付けます。

  3. 意味がわかるように質問を編集してください。ただし、テーブルからビュー コントローラーをプッシュする方法に沿って何かを尋ねているのではないかと思います。セグエを使用していて、ストーリーボードでセグエを作成し、ソース ビュー コントローラーと宛先ビュー コントローラーの両方に接続されている場合は-performSegueWithIdentifier:sender:、テーブルのビュー コントローラーに送信できます。つまり、テーブル ビュー コントローラーの-tableView:didSelectRowAtIndexPath:メソッドは-performSegueWithIdentifier:sender:、テーブル ビュー コントローラーから詳細ビュー コントローラーにつながるセグエの識別子を呼び出して指定する必要があります。シミュレーターを使用しているか、実際のデバイスでアプリを実行しているかは問題ではありません。

于 2012-11-29T15:10:44.057 に答える