4

を使用してテーブルを作成しようとしていますTTTableViewController。Instagramや他の多くのアプリケーションと同じように、セクションヘッダーにキャプションテキストとともに画像を表示したいと思います。からのサンプルを使用してからのTTNavigatorDemoデータを表示してみましたTTSectionedDatasource(これが正しい方法かどうかはわかりません。知っている場合は、より良い方法を提案してください)。通常の文字列としてセクション名/ヘッダーが含まれ、としてデータが含まれTTTableViewItemます。<UITableViewDelegate>プロトコルを実装してみましたviewForHeaderInSectionが、メソッドを使用してそれを達成しました。データはセクションから分離されています。Three20を使用して、ヘッダー/セクションビューをTableItemViewデータソースに渡し、実装できるようにするためのより良い方法はありますかTTTableViewDragRefreshDelegate。を実装するときに実装できませんでした<UITableViewDelegate>私のクラスのプロトコル。

今の私のクラス宣言は、次のようになります

@interface ImageTable : TTTableViewController <UITableViewDelegate> { }

次のような画像とテキストでセクションヘッダーを表示したいと思います。

インスタグラム

私は現在、を使用TTNavigatorCodeしてテーブルにデータを入力しています。これは次のとおりです。

   self.dataSource = [TTSectionedDataSource dataSourceWithObjects:
                               @"Food"
                               [TTTableViewItem itemWithText:@"Porridge" URL:@"tt://food/porridge"],
                               [TTTableTextItem itemWithText:@"Bacon & Eggs" URL:@"tt://food/baconeggs"],
                               [TTTableTextItem itemWithText:@"French Toast" URL:@"tt://food/frenchtoast"],
                               @"Drinks",
                               [TTTableTextItem itemWithText:@"Coffee" URL:@"tt://food/coffee"],
                               [TTTableTextItem itemWithText:@"Orange Juice" URL:@"tt://food/oj"],
                               @"Other",
                               [TTTableTextItem itemWithText:@"Just Desserts" URL:@"tt://menu/4"],
                               [TTTableTextItem itemWithText:@"Complaints" URL:@"tt://about/complaints"],
                               @"Other",
                               [TTTableTextItem itemWithText:@"Just Desserts" URL:@"tt://menu/4"],
                               [TTTableTextItem itemWithText:@"Complaints" URL:@"tt://about/complaints"],
                               nil];

メソッドを実装することで、似たようなものを作ることができました。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  return myCustomView;    
}

しかし、私のデータはモデルクラスからのものであり、ビューを生成してフォーマットされた方法でデータソースに追加したいので。Three20を使用して、セクションのデータの配列と、セクションの下の対応するデータの別の配列を指定する方法があるかどうかを知りたいですか?

あなたの助けは大歓迎です

ありがとう

4

1 に答える 1

1

デリゲートFOOTableDelegate.hを作成します

@interface FOOTableDelegate : TTTableViewDragRefreshDelegate 
{

}

- (UIView*) createHeaderView:(FOODataSource *)fDataSource forSectionID:(NSString *)secID;

@end

FOOTableDelegate.mファイル内

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
 {
    if (tableView.style == UITableViewStylePlain) 
        {
        if ([tableView.dataSource respondsToSelector:@selector(tableView:titleForHeaderInSection:)]) 
                {
            NSString* title = [tableView.dataSource tableView:tableView titleForHeaderInSection:section];
            if (title.length > 0) 
                        {
                UIView* header = [_headers objectForKey:title];

                if (nil != header)
                                {
                    header.alpha = 1;

                } 
                                else 
                                {
                    if (nil == _headers) 
                                        {
                        _headers = [[NSMutableDictionary alloc] init];
                    }

                    header = [self createHeaderView:tableView.dataSource forSectionID:title];
                    [_headers setObject:header forKey:title];
                }
                return header;
            }
        }
    }
    return nil;
}

- (UIView*) createHeaderView:(FeedDataSource *)fDataSource forSectionID:(NSString *)secID
{

     //do some code for header View

    return View;

}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    //return height for the Section Header
    return height;
}

これはあなたの問題を解決するのに役立ちます

于 2011-11-28T07:03:01.730 に答える