【发布时间】:2014-06-19 08:40:59
【问题描述】:
我正在尝试向 tableView 添加自定义单元格
我首先创建了一个带有 2 个标签“名称”和“描述”的 xib 文件,我已将其链接到控制器“customCellAchievementController”
当我尝试创建 tableView 时似乎找不到笔尖
知道这会在哪里失败吗?
我已将我的 xib 的类重新定义为控制器,我已将标识符更改为我在代码中使用的标识符,我已检查 xib 文件是否处于构建阶段/复制捆绑资源一切似乎都很好,我真的不明白......
这是我的代码
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [achievement count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *customCellIdentifier = @"CustomCell";
CustomCellAchievementController *cell = (CustomCellAchievementController *)[tableView dequeueReusableCellWithIdentifier:customCellIdentifier];
if(cell==nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.name.text= [achievement objectAtIndex:indexPath.row];
cell.description.text = [description objectAtIndex:indexPath.row];
return cell;
}
【问题讨论】:
-
您的 nib 文件的名称是什么?
-
您是否在 xcode 之外重命名了您的 xib?
-
您甚至可以检查 nib 文件是否已添加到 Xcode 目标的“构建阶段”选项卡的“复制包资源”部分下的包中
标签: ios objective-c uitableview