iOS:使用IB为以编程方式创建的UITableView创建自定义单元格

Bot*_*Bot 1 iphone uitableview ios5 xcode4.2

我有一个视图控制器,我以编程方式添加UITableView.但是,我想使用IB来创建我的自定义UITableViewCell,以便在我以编程方式创建UITableView.如果我在IB中的控制器中没有UITableView,我将如何以编程方式创建它?

我正在使用Xcode 4.2.1和故事板.

muf*_*ffe 6

只需像往常一样以编程方式创建UITableView,并在cellForRowAtIndexPath方法中使用

id cell = [dataTable dequeueReusableCellWithIdentifier:itemType];
if(!cell)
{
    NSArray *topLevelObject = [[NSBundle mainBundle] loadNibNamed:itemType owner:nil options:nil];
    cell = [topLevelObject objectAtIndex:0];
}
Run Code Online (Sandbox Code Playgroud)

其中itemType是一个带有xib文件名称的String.