2011-02-17 23 views
4

我正在嘗試使用TTTableViewController創建表。我想在部分標題中顯示圖像以及一些標題文本,類似於instagram和許多其他應用程序的功能。我嘗試使用TTNavigatorDemo中的示例顯示TTSectionedDatasource的數據(我不確定這是否是正確的方法,如果您知道的話,請提供一些更好的方法)。它包含部分名稱/標題爲常規字符串,數據爲TTTableViewItem。我嘗試執行<UITableViewDelegate>協議,並使用viewForHeaderInSection方法實現它,現在數據從section中分離出來,是否有更好的方法使用Three20,我可以通過它在數據源中傳遞我的Header/Section視圖和TableItemView,因爲它可以讓我執行TTTableViewDragRefreshDelegate,在我的課程中實施<UITableViewDelegate>協議時,我無法實現該功能。使用TTSectionedDataSource將圖像和標題文本添加到Three20表部分

我的類的聲明,現在,看起來像

@interface ImageTable : TTTableViewController <UITableViewDelegate> { } 

我想,以顯示與圖像和文本例如區段標題:

Instagram

我目前使用的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的方法,通過這種方法,我可以爲節指定一個數據的數組,而在另一個節的數據下指定另一個數組。

您的幫助是高度讚賞

感謝

+0

把你`TTTableview`爲'TTTableViewController <的UITableViewDelegate> {...}`比的loadView地說:`self.tableView.delegate =自我;`後實現' - (UIView的*)的tableView:(UITableView的*)的tableView viewForHeaderInSection :(NSInteger)部分{...}` – clenemt 2011-08-30 15:26:44

回答

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; 
} 

這將幫助你解決你的問題

相關問題