2012-10-17 36 views
0

嗨在我的應用程序我想創建tableview basen值動態我需要添加UItableView單元格與不同的控件,如(cell1與標籤,label2),(cell2與label1,textfield2),(cell3與label1,segment1)等。我在我的Xib中創建了UItableViewCell,但我無法動態加載它們。如果有人知道回覆我,謝謝如何在IOS中使用不同的TableViewCell創建TableView?

回答

1

您必須對cellForRowAtIndexPath方法執行此操作。像這樣的東西。

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

    if (indexPath.row == 0) { 
     return cell0; 
    } else if (indexPat.row == 1) { 
     return cell1; 
    } else if (indexPat.row == 2) { 
     return cell2; 
    } else if (indexPat.row == 3) { 
     return cell3; 
    } 

} 

cell0,cell1,cell2,cell3是您在界面構建器上創建並與IBOutlet鏈接的單元格。

+0

非常感謝你Jcesar – krishh

相關問題