2014-03-07 30 views
0

我将一列收藏夹 - 从详细信息视图 - 传递给(应该是)一个显示收藏夹的表视图。 第一个数组[在第一视图]是好的:数组对象正在加载但未连接到单元格

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 

和[在第二视图从所述第二阵列]在打印:

Printing description of self->FavsTwo: 
<__NSCFArray 0x1f9644a0>(
巴, 
巴, 
芭茅//巴茅, 
巴家, 
笆篓儿, 
巴, 
巴, 
巴, 
巴, 
巴, 
巴家, 
巴, 
巴, 
巴, 
巴家 
) 

还爽...

首破我得到的是在这里:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [FavsTwo count]; 
} 

,然后所有这些错误:

*** 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:' 
*** 

我的手机是这样的:

- (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; 


} 

试图将对象转换为字符串 - 真的不知道在那里它的失败

欢呼

+0

你得到解决? –

+0

@Himanshu Joshi都在下面的工作来加载表,但我仍然在行数崩溃 - 返回[FavsTwo计数]; * FIRST *单击继续在调试获取它加载.... – user3306356

+0

你记录'[FavsTwo计数];'? –

回答

1

你缺少自我dequeueReusableCellWithIdentifier:可能返回nil,如果它不能deque的细胞。

您需要检查,如果该细胞是nil

- (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:获得细胞:

- (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; 
} 
+0

这工作来加载表,但我仍然在行数崩溃 - 返回[FavsTwo计数]; * FIRST *单击继续在调试获取它加载.... – user3306356

+0

@ user3306356更新我的答案,也在Objectics-C不是不常见的启动与国会大厦的任何变量,所以'self.FavsTwo'应该是' self.favsTwo'。 – rckoenes

+0

必须具有投掷它的大小写......现在工作! – user3306356

2

的cellForRowAtIndexPath回报为零,如果不能ReusableCell,您应该创建一个单元格,其格式为CellIdentifier

试试这个:在tableView:numberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [self.FavsTwo count]; 
} 

- (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; 
} 
+0

这工作来加载表,但我仍然崩溃的行数 - 返回[FavsTwo计数]; * FIRST *单击继续在调试获取它加载.... – user3306356

+0

@ user3306356你能列出关于'返回[FavsTwo计数]' – simalone

+0

崩溃信息一定是rckoenes的关于它的大写的评论...谢谢尽管你的帮助! – user3306356

相关问题