2012-02-22 59 views
0

我正在處理一個需求,我需要有兩個列不應該是彼此獨立的TableView。所以我不尋找兩個獨立滾動的TableViews,而不是兩個可以滾動的列的單個TableView。在每一列中,我都需要填寫數據和截圖。UITableView與兩列,但不是兩個不同的TableViews

所以據我現在已經修改了代碼中的cellForRowAtIndexPath:

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

    static NSString *CellIdentifier = @"Cell"; 
    static NSString *secondCellIdentifier = @"Cell2"; 

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

    UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:secondCellIdentifier]; 

    if (cell2 == nil) { 
     cell2 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:secondCellIdentifier] autorelease]; 
    } 

    // Configure the cell... 

    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    cell.textLabel.text = [tableList objectAtIndex:indexPath.row]; 

    cell2.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

    cell2.textLabel.text = [tableList2 objectAtIndex:indexPath.row]; 

    UITableViewCell *twoColumnRowView = [[UITableViewCell alloc]init]; 

    [twoColumnRowView addSubview:cell]; 
    [twoColumnRowView addSubview:cell2]; 

    return twoColumnRowView; 
} 

但不幸的是,我沒有得到一個兩頁的表格,而不是我得到它可以被視爲在截圖一個奇怪的輸出。

Image

有人可以指導我在正確的方向。

P.S.我已經在同一個論壇和互聯網上瀏覽過關於同一主題的前幾篇文章,但沒有提供正確的解釋或例子。獲得有用的信息會很好。

感謝

回答

1

您必須創建一個具有您正在尋找佈局的自定義的UITableViewCell。然後,您可以在tableView:cellForRowAtIndexPath:方法中實例化它。

+0

但我已經在tableView:cellForRowAtIndexPath:方法中做了同樣的事情。糾正我,如果我錯了。另一方面,如果你有任何例子,那就很好 – 125369 2012-02-22 12:00:22

0

使您的自定義UITableViewCell類。在單元格內放置兩個UIButton並根據你的layOut設置它們。