your Second iOS App(4)—Displaying Information in the Detail Scene


Displaying Information in the Detail Scene

在細節場景中顯示信息


When iOS users tap a table row that includes a disclosure indicator, they expect to see a new screen that displays information related to the row item, typically in another table. In the BirdWatching app, each cell in the master scene’s table displays a bird-sighting item and a disclosure indicator. When users tap an item, a detail screen appears that displays the bird’s name and location and date of the bird sighting.

當iOS用戶輕拍包含揭露指示的行時,他們希望看到一個顯示這個行項的相關信息的新屏幕,通常它在另一個表中。在BirdWatching app中,在主場景的表格中的每個表單元都顯示一個bird-sighting 項和一個揭露指示。當用戶輕拍項時,細節屏幕出現,它顯示鳥的名字、地點以及bird sighting的日期。

In this chapter, you create the detail scene that displays the information about the selected bird sighting.

在本章中,你創建一個用來顯示被選擇的bird sighting 信息的細節場景。

Edit the Detail View Controller Code

編輯細節視圖控制器代碼


The detail scene should display the information from the BirdSighting object that’s associated with the selected table cell. Unlike the work you did on the master scene, you’ll write the detail view controller code first and design the scene on the canvas in a later step.

細節場景將顯示BirdSighting對象的信息,這些信息與選中的表單元相關聯。與你在主場景所做的不同,你將首先編寫細節視圖控制代碼,下一步在畫布上設計場景。

To customize the detail view controller header file

自定義細節視圖控制器頭文件


1. 在工程導航器中選擇BirdsDetailViewController.h。

2. 在#import@interface語句之間添加BirdSighting類的前向聲明。

@class BirdSighting;

3. 將默認細節視圖控制器的父類變更爲UITableViewController。

完成後,@interface語句將如下所示:

@interface BirdsDetailViewController:UITableViewController


Note that changing the default detail scene from a generic view controller to a table view controller is a design decision; that is, this change is not required for the app to run correctly. The main reason for this design decision is that using a table to display the bird sighting details provides a user experience that is consistent with the master scene. A secondary reason is that it gives you the opportunity to learn how to use static cells to design a table.

注意,將默認的細節場景從通用視圖控制器改變爲表視圖控制器是一個設計決策。也就是說,這個改變不是爲了app 正確運行所要求的。這個設計決策的主要原因是,使用表格來顯示bird sighting 的細節提供給用戶一種與主場景關聯的體驗。第二個原因是,它讓你有機會學習如何使用靜態表單元來設計表格。

4.Declare properties that refer to the BirdSighting object and its properties.

4. 聲明屬性指向BirdSighting對象和它的屬性。

You don’t need the default
detailItem and detailDescriptionLabel property declarations provided by the template. Replace these with the following property declarations:

你不需要模板提供的默認的detailItemdetailDescriptionLabel屬性聲明。用下面的屬性聲明代替它們。

@property (strong, nonatomic) BirdSighting *sighting;

@property (weak, nonatomic) IBOutlet UILabel *birdNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *locationLabel;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;


Xcode displays additional problem indicators after you replace the default properties because the code still references the old properties.

在你替代了默認的屬性之後,Xcode 顯示了問題指示,因爲有代碼仍然指向舊的屬性。

In the detail scene implementation file, you first need to give the detail scene access to objects of type BirdSighting. Then, you need to implement two of the default methods.

在細節場景實現文件中,首先你需要讓細節場景訪問BirdSighting類型的對象。然後,你需要實現兩個默認的方法。

To give the detail scene access to BirdSighting objects

讓細節場景訪問BirdSighting 對象


1.Select BirdsDetailViewController.m in the project navigator.

1.在工程導航器中選擇BirdsDetailViewController.m。

Xcode displays red problem indicators next to each usage of the
detailItem and detailDescriptionLabel symbols because you removed the property declarations for them

Xcode 在每個使用detailItemdetailDescriptionLabel旁邊顯示紅色的問題指示符號,因爲你移除了它們的屬性聲明。


2.At the beginning of the file, import the BirdSighting header file by adding the following code line:

2. 在文件開始的開始地方,通過添加如下代碼行來import BirdSighting頭文件。

#import “BirdSighting.h”


By default, the BirdsDetailViewController implementation file includes stub implementations of the setDetailItem and configureView methods. Notice that the setDetailItem method is a custom setter method for the detailItem property that was provided by the template (and that you removed in “To customize the detail view controller header file”). The reason the template uses a custom setter method—and not the default setter that Xcode can synthesize—is so that setDetailItem can call configureView.

默認情況下,BirdsDetailViewController實現文件包含了setDetailItemconfigureView方法的存根(stub)實現。注意,setDetailItem方法是模板提供的detailItem屬性自定義的setter方法。讓模板使用定製的setter方法——而不是使用默認的Xcode 合成的setter方法——的原因是setDetailItem能調用configureView

In this tutorial, the detail item is a BirdSighting object, so the sighting property takes the place of the detailItem property. Because these two properties play similar roles, you can use the structure of the setDetailItem method to help you create a custom setter for the sighting property.

在本教程中,細節項是BirdSighting對象,所以sighting屬性取代detailItem屬性。因爲這連個屬性承擔相似的任務,你能使用setDetailItem的結構方法來幫助你自定義sighting屬性的setter方法。

To create a custom setter method for the sighting property

爲sighting屬性創建自定義的setter方法


In BirdsDetailViewController.m, replace the setDetailItem method with the following code:

BirdsDetailViewController.m中,用下面的代碼替換setDetailItem方法。

-(void) setSighting:(BirdSighting *)newSighting

{

if (_sighting != newSighting){

_sighting = newSighting;


// Update the view.

[self configureView];

}

}

The configureView method (which is called in both the new setSighting method and the default viewDidLoad method) updates the UI of the detail scene with specific information. Edit this method so that it updates the detail scene with data from the selected BirdSighting object.

configureView方法(它既被新的setSighting方法調用也被默認的viewDidLoad方法調用。)利用特殊的信息更新細節場景的UI。編輯這個方法,以便它使用從選擇的BirdSighting對象所得數據來更新細節場景。

To implement the configureView method

實現配置視圖方法


In BirdsDetailViewController.m, replace the default configureView method with the following code:

BirdsDetailViewController.m中,使用下面的代碼來替代configureView方法。

-(void)configureView

{

// Update the user interface for the detail item.

BirdSighting *theSighting = self.sighting;


static NSDateFormatter *formatter = nil;

if (formatter == nil){

formatter = [[NSDateFormatter allco] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

}

if (theSighting){

self.birdNameLabel.text = theSighting.name;

self.locationLabel.text = theSighting.location;

self.dateLabel.text = [formatter stringFromDate:(NSDate *)theSighting.date];

}

}


In the next section, you’ll lay out the detail scene on the canvas.

在接下來的部分中,你將在畫布上佈置細節場景。

Design the Detail Scene

設計細節場景


In the previous section, you changed the parent class of the template-provided detail view controller from UIViewController to UITableViewController. In this section, you replace the default detail scene on the canvas with a new table view controller from the object library.

在前面的部分,你把模板提供的細節視圖控制器的父類從UIViewController改成UITableViewController。在本部分,你將從對象庫中選擇新的表視圖控制器來代替默認的細節場景。

To replace the default UIViewController scene with a UITableViewController scene

使用UITableViewController 場景替換默認的UIViewController場景

1.Select MainStoryboard.storyboard in the project navigator to open it on the canvas.

1. 在工程導航器中選擇MainStoryboard.storyboard,在畫布中打開它。

2.Select the detail scene and press Delete.

2. 選擇細節場景並按下Delete。

To make sure that you delete the scene itself—and not just an element in the scene—you need to make sure that the entire scene is selected on the canvas. An easy way to do this is to select the scene’s view controller in the document outline. For example, when you select Birds Detail View Controller - Detail in the document outline, you see something like this:

確保你刪除的是這個場景的自身,而不是這個場景中的元素,你需要確保在畫布中整個場景都被選中。可以在文檔大綱選擇場景的視圖控制器來方便的實現這個操作。例如,當你在文檔大綱中選擇Birds Detail View Controller - Detail的時候,會看到如下效果:

3.Drag a table view controller from the object library to the canvas.

3. 從對象庫中拖拽表視圖控制器到畫布中。

4.With the new scene still selected on the canvas, click the Identity button in the utility area to open the Identity inspector.

4. 在畫布中仍然選中新的場景,在工具區點擊身份按鈕來打開身份檢查器。

If necessary, select Table View Controller in the document outline to ensure that the scene is selected on the canvas.

如有必要,在文檔大綱中選擇Table View Controller 來確保畫布中場景被選擇。

5.In the Custom Class section of the Identity inspector, choose BirdsDetailViewController in the Class pop-up menu.

在身份檢查器的Custom Class 部分,在Class 彈出菜單中選擇BirdsDetailViewController。

When you delete a scene from the canvas, all segues to that scene also disappear. You need to reestablish the segue from the master scene to the detail scene so that the master scene can transition to the detail scene when the user selects an item. Make sure that you can see both the master scene and the new detail scene on the canvas.

當你從畫布中刪除場景的時候,所有這個場景的segues也將消失。你需要重建從主場景到細節場景的segue,以便當用戶選擇一個項的時候主場景能夠轉換到細節場景。確保你能夠在畫布上同時看到主場景和新的細節場景。

To create a segue from the master scene to the detail scene

創建從主場景到細節場景的segue


1.Control-drag from the table cell in the master scene to the detail scene.

在主場景中,從表單元按住Control拖拽到細節場景。

In the Selection Segue area of the translucent panel that appears, select Push. A selection segue occurs when the user selects the table row; a push segue causes the new scene to slide over the previous scene from the right edge of the screen. (The Accessory Action area lists segues that can be triggered when the user interacts with a table accessory, such as a detail disclosure button.)

在出現的半透明面板中的Selection Segue區域,選擇Push。當用戶選擇表的行的時候,一個segue選擇將發生。push segue導致新的場景從屏幕的右側滑入覆蓋前一個場景。(附屬行動區域列出了segue能在用戶與表附件交互的時候被觸發的動作,例如細節揭露按鈕)。
Notice that Xcode automatically displays a navigation bar in the detail scene. This is because Xcode knows that the source scene—in this case, the master Bird Sightings scene—is part of a navigation controller hierarchy, and so it simulates the appearance of the bar in the detail scene to make it easier for you to design the layout.

注意,Xcode自動在細節場景顯示導航條。這是因爲Xcode知道源場景——在這個例子中,主Bird Sightings場景——是導航控制器層級的一部分,所以它在細節場景中模擬這個條的外觀來是你方便的設計佈局。

2.On the canvas, select the push segue you just created.

在畫布上,選擇你剛創建的push segue。

3.In the Attributes inspector, enter a custom ID in the Identifier field.

在屬性檢查器中,在識別符字段輸入定製的ID。

By convention, it’s best to use an identifier that describes what the segue does. In this tutorial, use
ShowSightingDetails because this segue reveals sighting details in the detail scene.

按照慣例,最好使用描述segue功能的詞作爲標識符。在本教程中,使用ShowSightingDetails,因爲這個segue在細節場景中揭示sighting細節。
If a scene can transition to different destination scenes, it’s important to give each segue a unique identifier so that you can differentiate them in code. In this tutorial, the master scene can transition to the detail scene and to the add scene (which you’ll create in
“Enabling the Addition of New Items”), so you need to have a way to distinguish between these two segues.

如果場景能轉換到不同目標的場景,那麼給每個場景一個獨特的標識符就非常重要,以便你能夠在代碼中區分它們。在本教程中,主場景等夠轉換到細節場景和添加場景(你將在“Enabling the Addition of New Items”中創建它),所以你需要有一個方法力氣區分這兩個segues。

Although the details about a bird sighting vary, the app should always display them in the same format—specifically: name, date, and location. Because you never want the detail table to display information in a different layout, you can use static table cells to design this layout on the canvas.

景觀關於bird sighting的細節不同,但app應該總用明確的相同的格式來顯示它們:名字、日期以及地點。因爲你永遠也不希望細節表顯示信息的時候用不同的佈局,你能使用靜態的表單元來在畫布上設計這個佈局。

By default, a new table view controller scene contains a table that uses prototype-based cells. Before you design the detail table layout, change its content type.

默認情況下,一個新的表視圖控制器場景包含一個使用基本原形表單元的表格。在你開始設計細節表佈局之前,改變它的內容樣式。

To change the detail table-view content type

改變細節表視圖內容樣式。

1.On the canvas, select the table view in the detail scene.

在畫布上,在細節場景中選擇表視圖。

2.In the Attributes inspector, choose Static Cells in the Content pop-up menu.

在屬性檢查器中,在Content彈出菜單中選擇Static Cells。

When you change the content type of a table view from dynamic prototypes to static cells, the resulting table automatically contains three cells. By coincidence, three happens to be the number of table rows that you want to display in the app. You could design each cell separately, but because each cell uses the same layout, it’s more convenient to design one of them and copy it to create the others.

當你把表視圖的內容樣式從動態原形改變爲靜態表單元的時候,表格自動的包含三個表單元。巧合的是,三個恰好是你想在app總顯示的錶行的數目。你能分別設計每個表單元,但因爲每個表單元都是用相同的佈局,所以設計它們中的一個然後複製創建其他幾個更爲方便。

To design one static table cell and copy it

設計一個靜態表單元然後複製它。


1.Remove two of the cells by selecting them and pressing Delete.

通過選中兩個表單元然後點擊Delete來刪除它們。

2.Select the remaining cell (if necessary) and choose Left Detail in the Style pop-up menu of the Table View Cell Attributes inspector.

選擇剩下的的表單元(如有必要)並且在Table View Cell屬性檢查器中的Style彈出菜單中選擇Left Detail。


3.In the document outline, select Table View Section.

在文檔大綱中,選擇Table View Section。

4.In the Table View Section area of the Attributes inspector, use the Rows stepper to increase the number of rows to 3.

在屬性檢查器的Table View Section區域中,使用行步進器來把行數增加到3.

5.In each cell, double-click the title label and enter the appropriate description.

在每個表單元中,雙擊標題標籤然後輸入恰當的描述。

In the top cell, enter
Bird Name; in the middle cell, enter Location; and in the bottom cell, enter Date.

在表單元的頂部,輸入Bird Name;在表單元的中間,輸入Location;在表單元的底部,輸入Date。

After you finish laying out the cells in the table, the detail scene should look similar to this:

在完成表格中的表單元的佈局後,細節場景將看上去如下所示:

When the app runs, you want the right-hand label in each cell to display one of the pieces of information in the selected BirdSighting object. Earlier, you gave the detail view controller three properties, each of which accesses one property of a BirdSighting object. In this step, connect each label in the detail scene to the appropriate property in the detail view controller.

當app運行的時候,你希望每個表單元的右側的標籤顯示你選擇的BirdSighting對象的信息的一部分。之前,你給細節視圖控制器三個屬性,它們每個都訪問BirdSighting對象的一個屬性。在這一步驟,細節場景中的每個標籤都與細節視圖控制器中的恰當的屬性連接。

To connect the detail text labels to the detail view controller’s properties

連接細節文本標籤到細節視圖控制器的屬性上


1.In the Table View section of the document outline, locate the table view cell that contains the Bird Name label (it should be the first one).

在文檔大綱的Table View 部分,定位包含Bird Name Label(它應該是第一個)的表視圖單元。

2.Control-click the Label - Detail object listed below Label - Bird Name.

按住Control並點中Lable-Bird Name後面列出的Label-Detail對象。

3.In the translucent panel that appears, Control-drag from the empty circle in the New Referencing Outlet item to the BirdsDetailViewController object in the scene dock on the canvas.

在出現的半透明面板中,按住Control鍵並點中在New Referencing Outlet項的空心圓拖拽到畫布上的場景dock中的BirdsDetailViewController對象上。

The scene dock is the bar below the scene. When the scene or any element within it is selected, the scene dock typically displays three proxy objects: An orange cube that represents the first responder, a yellow sphere that represents the scene’s view controller object, and a green square that represents the destination of an unwind segue. An unwind segue is a segue you use to return to an existing scene without instantiating a new view controller object. (Later, you’ll be using an unwind segue to add to the master list information about a new bird sighting.) At other times, the scene dock displays the scene’s name.

場景dock是在場景下面的欄。當場景或者其中的元素被選中的時候,這個場景dock代表性的顯示三個代理對象:橙色的立方體代表第一響應者,黃色球體代表場景的視圖控制器對象,綠色的正方形代表unwind segue的目的地。unwind segue是你用來返回到已經存在的場景,這個場景沒有實例化一個新的視圖控制器對象,的segue。(稍後,你將使用unwind segue 來添加有關新的bird sighting的信息到主列表。)在其他時候,場景dock顯示場景的名字。
As you Control-drag from the New Referencing Outlet item in the translucent panel, you see something like this:

當你從半透明面板中按住Control並拖拽New Referencing Outlet項,看上去如下所示:

4.In the Connections panel that appears when you release the Control-drag, choose birdNameLabel.

當你釋放拖拽的時候顯示的連接面板中,選擇birdNameLabel。

5.Perform steps 1, 2, and 3 with the detail label in the Location cell. This time, choose locationLabel in the Connections panel.

在Location cell中細節標籤執行1、2和3步驟。這詞,在連接面板中選擇locationLabel。

6.Perform steps 1, 2, and 3 with the detail label in the Date cell. This time, choose dateLabel in the Connections panel.

在Date cell的細節標籤中執行1、2和3步驟,這次,在連接面板中選擇dateLabel。


All the elements of the detail scene’s UI seem to be connected with the code, but the detail scene still doesn’t have access to the BirdSighting object that represents the item the user selected in the master list. You fix this in the next step.

所有細節場景的UI元素看上去應該連接代碼,但是細節場景仍然沒有訪問BirdSighting對象,這個對象代表用戶在主列表中選擇的項。你將在下一個步驟中解決這個問題。

Send Data to the Detail Scene

發送數據到細節場景


Storyboards make it easy to pass data from one scene to another using the prepareForSegue method. This method is called when the first scene (the source) is about to transition to the next scene (the destination). The source view controller can implement prepareForSegue to perform setup tasks, such as passing to the destination view controller the data it should display in its views.

故事板使用prepareForSegue方法使得從一個場景傳遞數據到另一個場景變得容易。這個方法是在第一個場景(源場景)要轉換到另一個場景(目標場景)的時候被調用。源視圖控制器能夠實現prepareForSegue來執行設置任務,例如,傳遞到目標視圖控制器的數據將顯示在其視圖上。

Note: The default implementation of prepareForSegue that’s provided by the template uses the default setDetailItem method in the detail view controller. Because you replaced setDetailItem with setSighting (in “To create a custom setter method for the sighting property”), you might see a problem indicator telling you that setDetailItem has no implementation. You’ll fix this problem when you implement the prepareForSegue method in the next step.

注意:默認實現的prepareForSegue,它是通過模板提供,使用在細節視圖控制器中的默認setDetailItem方法。因爲你使用setSighting來代替setDetailItem(在“To create a custom setter method for the sighting property”),你可能看到了問題指示器告訴你setDetailItem沒有實現。你將在下一步實現prepareForSegue方法後解決這個問題。


In your implementation of the prepareForSegue method, you need the ID that you gave to the segue between the master scene and the detail scene. In this tutorial, the ID is already part of the code listing for the method; when you write an app from scratch, you need to copy the ID from the segue Attributes inspector.

在你實現prepareForSegue方法中,你需要你給出的主場景和細節場景之間segue的ID。在本教程中,這個ID已經是這個方法的代碼清單的一部分;當你從頭編寫app的時候,你需要複製segue 屬性檢查器中的ID。

To send setup information to the detail scene

發送設置信息到細節場景


1.Select BirdsMasterViewController.m in the project navigator to open the file in the editor.

在工程導航器中選擇BirdsMasterViewController.m來在編輯器中打開文件。

2.Make sure the detail view’s header file is imported.

卻表細節視圖的頭文件被import。

Near the top of the file, you should see the following code line:

在文件的頂部附近,你應該看到如下代碼行:

#import “BirdsDetailViewController.h”

2.In the @implementation block, replace the default prepareForSegue method with the following code:

@implementation代碼塊,用下面的代碼來代替默認的prepareForSegue方法:

-(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];

}

}


After a few seconds, Xcode removes all the remaining problem indicators.

幾秒鐘後,Xcode已掉了所有剩下的問題指示。

Build and run the project. In Simulator, you should see the placeholder data that you created in the BirdSightingDataController class displayed in the master scene. Notice that the master scene no longer displays the Edit button and Add button (+) because you removed the code that created these buttons from BirdsMasterViewController.m.

構建並運行工程。在模擬器中,你應該能在主場景中看到你在BirdSightingDataController類中創建佔位數據。注意,主場景不再顯示編輯按鈕和(+)按鈕,因爲你移除了在BirdsMasterViewController.m創建的這些按鈕的代碼。

In the master scene, select the placeholder item. The master scene transitions to the detail scene, which displays information about the item in the table configuration that you designed. Click the back button that appears in the upper-left corner of the screen to return to the master list.

在主場景中,選擇佔位符項。主場景將轉換到細節場景,它顯示你設計的表格配置的項的信息。點擊在屏幕左上角的返回按鈕,返回到主列表。

In the next chapter, you’ll design a new scene in which user can enter information about a new bird sighting and add it to the master list. For now, quit iOS Simulator.

在下一章中,你將設計新的場景,這個場景中用戶可以輸入關於新的bird sighting 信息並添加它到主列表中。現在,退出iOS模擬器。

Recap

回顧


In this chapter, you customized the template-provided detail view controller so that it displays the details about the item the user selects in the master list. You edited the detail view controller code to change the parent class to UITableViewController, added properties that refer to bird-sighting details, and implemented methods that update the UI.

在本章中,你自定義了模板支持的細節視圖控制器,使它顯示關於用戶在主列表中選擇的項的細節。你編輯細節視圖控制器的代碼來把父視圖改爲UITableViewController,添加屬性指向bird-sighting 細節,並且實現方法來配置UI。

On the canvas, you replaced the template-provided detail scene with a table view controller. When you did this, you learned that you had to re-create the segue from the master scene to the detail scene. Because the detail scene should always display the same configuration of data, you used a static-content based table to lay out three table cells—one cell for each bird sighting detail.

在畫布上,你使用表視圖控制器替換掉模板提供的細節場景。當你完成後,你學習到你必須重建一個從主場景到細節場景的segue。因爲細節場景應該總是顯示相同的數據配置,你使用基於表格的靜態內容來佈局三個表單元——一個表單元對應一個bird sighting 細節。

Finally, you implemented the prepareForSegue method in the master view controller, which allowed you to pass to the detail scene the BirdSighting object that’s associated with the user’s selection in the master list.

最後,你在主視圖控制器中實現了prepareForSegue方法,它允許你傳遞BirdSighting對象到細節場景,這個BirdSighting對象與用戶在主列表中選擇相關。

At this point in the tutorial, the code in BirdsDetailViewController.h should look like this:

本章到現在爲止,BirdsDetailViewController.h的代碼應如下所示:

#import <UIKit/UIKit.h>

@class BirdSighting;

@interface BirdsDetailViewController:UITableViewController

@property (strong, nonatomic)BirdSighting *sighting;

@property (weak, nonatomic) IBOutlet UILabel *birdNameLabel;

@property (weak, nonatomic) IBOutlet UILabel *locationLabel;

@property (weak, nonatomic) IBOutlet UILabel *dateLabel;

@end


The code in BirdsDetailViewController.m should look similar to this (not including template-provided code that you don’t edit in this tutorial):

BirdsDetailViewController.m中的代碼應如下所示(不包括在本教程中不需要的模板提供的代碼):

#import "BirdsDetailViewController.h"

#import "BirdSighting.h"

@interface BirdsDetailViewController()

-(void)configureView;

@end


@implementation BirdsDetailViewController

#pragma mark - Managing the detail item

-(void)setSighting:(BirdSighting*)newSighting

{

if (_sighting != newSighting){

_sighting = newSighting;

// Update the view.

[self configureView];

}

}


-(void)configureView

{

// Update the user interface for the detail item.

BirdSighting  *theSighting = self.sighting;

static NSDateFormatter *formatter = nil;

if(formatter == nil){

formatter = [[NSDateFormatter alloc] init];

[formatter setDateStyle:NSDateFormatterMediumStyle];

}

if(theSighting){

self.birdNameLabel.text = theSighting.name;

self.locationLabel.text = theSighting.location;

self.dateLabel.text = [formatter stringFromDate:(NSDate*)theSighting.date];

}

}

-(void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.


[self configureView];

}

@end


The prepareForSegue method in BirdsMasterViewController.m should look similar to this (edits that you made to this file earlier in the tutorial are not shown):

BirdsMasterViewController.m中的prepareForSegue方法應該如下所示(你在之前教程中編輯的代碼不再顯示):

#import "BirdsDetailViewController.h"

-(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


Next

Previous




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章