2010-12-06 22 views

答えて

2

まず、インターフェイスファイル内のUITableViewのIBOutletオブジェクトを取得し、インターフェイスビルダーを使用してバインドする必要があります。インターフェイスビルダプロパティでUITableViewのデリゲートとデータソースを設定します。

プロジェクトで次のコードを行います。 .hファイルで

@interface RootViewController : UITableViewController<UITableViewDelegate,UITableViewDataSource> { 

    IBOutlet UITableView *tblView; 
} 

.mファイルで:

// Customize the number of sections in the table view. 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

//はテーブルビュー内の行数をカスタマイズします。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return n;// n for number of row. 
} 

//表ビューセルの外観をカスタマイズします。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell. 

    return cell; 
} 
関連する問題