2011-11-08 13 views
0

私のコードは他とは少し異なりますが、動作します。Xcodeでグループ化されたテーブルビューにセクションを追加する

私はアプリのコーディングに新しいですが、私はセクションに これらのいくつかを追加したい:

enter image description here

だから、それらのいくつかは、それぞれに小さなタイトルと自分のグループを持っています。

しかし、私のコードは次のようになります。

enter image description here

と私は右のそれを行うに挿入するのか分かりません。

(その画像の下半分を使用すると、テーブルビューから何かを選択すると、詳細ビ​​ューに表示されていることを、詳細ビュー内の画像である。)

(私は、Xcodeのは、私のコード内のエラーを示して知っていますそれでも動作します)。

誰でも助けてくれますか?あなたが好きなものと

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    //Here you must return the number of sectiosn you want 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    //Here, for each section, you must return the number of rows it will contain 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    //For each section, you must return here it's label 
    if(section == 0) return @"header 1"; 
    ..... 
} 

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

    static NSString *CellIdentifier = @"Cell"; 

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

    // Set up the cell... 
    cell.text = // some to display in the cell represented by indexPath.section and indexPath.row; 

    return cell; 
} 

は、あなたがあなたのデータを配置することができます:一つの配列をあなたには、いくつかのUITableView方法とデリゲートメソッドを実装する必要が

答えて

1

は(そしてもちろん、クラスのデリゲートとしてクラスを設定します)各セクションごとに、サブアレイを持つ1つの大きな配列、...あなたが望むように。上記の方法から必要な値を返すことができる限り、Antthingは問題ありません。

+0

ありがとうございます!私はヘッダーを持っていますが、ヘッダーの下にデータはありません。スクリーンショット:http://cl.ly/3M1J230W0r0T0844102X – ifraaank

+0

@ user1036372:あなたのtableViewコードを与えて、私は見てみましょう。これは、numberOfRowsInSectionの戻り値が不正であるか、不正なcellForRowAtIndexPathの解析のためにbebする必要があります – Oliver

関連する問題