自定义单元格和UITableViewCell问题

时间:2011-05-14 00:38:12

标签: iphone uitableview

新手在这里,只是学习!

我正在尝试使用三个自定义单元格创建一个表格视图应用程序。每个单元格都需要在左侧有一个标签和一个图像(到目前为止,我只对标签部分感到烦恼)。到目前为止this guide

非常有用。我创建了一个包含三个项目的数组并让它加载得很好,但是当我尝试实现一个自定义单元格时,一切都破了。对于这部分代码:

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

    static NSString *CellIdentifier = @"CustomCell";

    CustomCell *cell = (CustomCell *)
    [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil){
        NSArray *topLevelObjects = [[NSBundle mainBundle]
                                    loadNibNamed:@"CustomCell"
                                    owner:nil options:nil];

        for(id currentObject in topLevelObjects)
            {
                if ([currentObject isKindOfClass:[UITableViewCell class]])
                {
                    cell = (CustomCell *) currentObject;
                    break;
                }
        }
    }

    cell.issue.text = array objectAtIndex:[indexPath.row];

    return cell;
}

我收到错误Unused variable CellIdentifierCustomCell undeclaredExpected expression before ) tokenControl reaches end of non-void function

我不知道是什么会引起这些问题,就我所知道的事情而言,我有点死路一条。对不起我的新闻,任何指向正确的方向都将不胜感激。

编辑: Heyooo!谢谢,导入CustomCell修复了一大堆问题!现在运行它之前没有可见的错误,但是当我尝试运行它时,我只是被发送到

// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [array count];

红色箭头指向返回[数组计数];

我当前的数组代码是:

- (void)viewDidLoad {
    [super viewDidLoad];

    array = [[NSMutableArray alloc] init];
    [array addObject:@"Eleven"];
    [array addObject:@"Ten"];
    [array addObject:@"Nine"];
哇,这是一个多么有帮助和反应灵敏的社区。不能够感谢你。

2 个答案:

答案 0 :(得分:3)

您需要的只是CustomCell类的导入声明。

#import "CustomCell.h" // for example.

答案 1 :(得分:0)

你可能只是错过了一步。您是否制作了Custom Cell.m,Custom Cell.m和Custom Cell.xib文件?如果是这样,您将需要导入头文件。

#import "CustomCell.h"
相关问题