CREATING THE APPLICATION

In this section, you create the user interface for the application. You'll use a Table View to display the users that you have discovered on the network. As users are discovered, they will be added to the Table View.

TRY IT OUT: Creating the Application's UI

  1. Using Xcode, create a Single View Application (iPhone) project and name it Bonjour. Use this project name as the Class Prefix and ensure that you have the Use Automatic Reference Counting option unchecked.
  2. Select the BonjourViewController.xib file to edit it in Interface Builder. Populate the View window with the following views (see Figure 18-1):
    • Label (set its text to Discovered Users and Debug statements)
    • Table View
    • Text View

    image

    FIGURE 18-1

  3. In the BonjourViewController.h file, add the following bold statements:
    #import <UIKit/UIKit.h>
    
    @interface BonjourViewController : UIViewController
    <UITableViewDelegate, UITableViewDataSource>
    {
        IBOutlet UITableView *tbView;
        IBOutlet UITextView *debug;
    }
    
    @property (nonatomic, retain) UITableView *tbView;
    @property (nonatomic, retain) UITextView *debug;
    
    -(void) resolveIPAddress:(NSNetService *)service;
    -(void) browseServices;
    
    @end
  4. In the BonjourViewController.xib window, perform the following connections:
    • Control-click the File's Owner item and drag and drop it over the TableView. Select tbView.
    • Control-click the File's Owner item and drag and drop it over the Text View. Select debug.
    • Right-click the Table View and connect the dataSource outlet to the File's Owner item.
    • Right-click the Table View and connect the delegate outlet to the File's Owner item.

    image

    FIGURE 18-2

  5. To verify that all the connections are made correctly, right-click the File's Owner item and view its connections (see Figure 18-2).

How It Works

Because you'll use the Table View to display the list of users discovered on the network, you need to set the dataSource and delegate outlets to the File's Owner item. The Text View is used to show the various things happening in the background. This is very useful for debugging your application and understanding what happens as services are discovered on the network.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.223.127