2014-09-12 123 views
-1

我试图从代码创建一个UITableView(以前从未这样做过),它将显示在UIPopover中。我想列出目录的内容(仅限文件名)。这是我的代码:如何以编程方式配置UITableViewCell?

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellIdentifier = @"FilenameCell"; 

    UITableViewCell *cell = (UITableViewCell *)[theTableView dequeueReusableCellWithIdentifier:cellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

    cell.textLabel = fileList[0]; 

    return cell; 
} 

这显然不工作,我收到一个错误:“分配到只读属性”。所以,问题是:在这种情况下如何设置单元的数据?

+0

'dequeueReusableCellWithIdentifier的转换:'的结果是无用的。 – vikingosegundo 2014-09-12 22:37:37

回答

1

你需要设置你的textLabeltext属性(我敢肯定,只是在你的情况下,一个错字):

cell.textLabel.text = fileList[0]; 
+0

Awww ..我也知道得更好!解决了问题......谢谢......: - { – SpokaneDude 2014-09-12 22:36:36

相关问题