首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数组对象加载但未连接到单元格

数组对象加载但未连接到单元格
EN

Stack Overflow用户
提问于 2014-03-07 08:45:30
回答 2查看 53关注 0票数 0

我将一个收藏夹数组--从一个细节视图--传递给(应该是什么)一个表视图,单独显示收藏夹。第一个视图中的第一个数组是可以的:

代码语言:javascript
复制
Array found. Contents: (
    "\U5df4",
    "\U5df4",
    "\U82ad\U8305//\U5df4\U8305",
    "\U5df4\U5bb6",
    "\U7b06\U7bd3\U513f",
    "\U5df4",
    "\U5df4",
    "\U5df4",
    "\U5df4",
    "\U5df4",
    "\U5df4\U5bb6",
    "\U5df4",
    "\U5df4",
    "\U5df4"
)
Number of items in my array is: 15

并从第二个视图中的第二个数组中打印它。

代码语言:javascript
复制
Printing description of self->FavsTwo:
<__NSCFArray 0x1f9644a0>(
巴,
巴,
芭茅//巴茅,
巴家,
笆篓儿,
巴,
巴,
巴,
巴,
巴,
巴家,
巴,
巴,
巴,
巴家
)

也很酷..。

我得到的第一个休息是在这里:

代码语言:javascript
复制
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
     return [FavsTwo count];
}

然后所有这些错误:

代码语言:javascript
复制
*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:6235
 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
***

我的手机是这样的:

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    NSString *cellValue = [self.FavsTwo objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;
    return cell;


}

试图将对象转换为字符串-不太确定它在哪里失败

干杯

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-07 08:50:27

你在tableView:numberOfRowsInSection:中失去了自我

代码语言:javascript
复制
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return [self.FavsTwo count];
}

如果dequeueReusableCellWithIdentifier:不能破坏一个单元格,它可以返回nil

您需要检查单元格是否为nil

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(!cell) {
        cell = [UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]
    }    

    NSString *cellValue = [self.FavsTwo objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

    return cell;
}

如果您使用过registerClass:forCellReuseIdentifier:registerNib:forCellReuseIdentifier:.The,则需要使用dequeueReusableCellWithIdentifier:forIndexPath:获取单元格。

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    NSString *cellValue = [self.FavsTwo objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

   return cell;
}
票数 1
EN

Stack Overflow用户

发布于 2014-03-07 08:49:00

cellForRowAtIndexPath返回零,如果不能ReusableCell,则应创建带有CellIdentifier的单元格。

试试这个:

代码语言:javascript
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    NSString *cellValue = [self.FavsTwo objectAtIndex:indexPath.row];
    cell.textLabel.text = cellValue;

    return cell;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22245338

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档