【问题标题】:populating a groupped uitableView with sections dynamically用部分动态填充分组的 uitableView
【发布时间】:2012-06-12 10:15:40
【问题描述】:

我正在开发一个包含分组 UITableView 并使用 XMLparser 获取其数据的视图。

我的 XMLParser 将 NSDictionary 数据存储在 NSArray 中。

在 cellForRowAtIndexPath 我写这个是为了动态填充 UITableView:

-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellArticle";


UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}
//configuration cellule

if(mParser.summaryArray == nil||[mParser.summaryArray count]==0)
{
//do nothing
}
else {
NSDictionary *sommaire=[mParser.summaryArray objectAtIndex:0];
cell.textLabel.text=[NSString stringWithFormat:@"%@",[sommaire objectForKey:kArticle]];
[mParser.summaryArray removeObject:[mParser.summaryArray objectAtIndex:0]];
}


return cell;
}

问题是,当视图加载时,单元格设置正确,但是当我向下滚动表格时,单元格混合在一起,其中一些丢失了。 此外,当我达到表限制时,它会崩溃并返回此错误:

* -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] 中的断言失败,/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061

* 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView:cellForRowAtIndexPath:”返回一个单元格:'**

请问有什么问题吗?

【问题讨论】:

    标签: ios dynamic uitableview


    【解决方案1】:

    不是你的// do nothing,而是你宁愿在那里做一个return nil; 吗?否则,您只需返回一个填充有空白标签文本的单元格。

    编辑

    你能在这里添加一个 NSLog():

    cell.textLabel.text=[NSString stringWithFormat:@"%@",[sommaire objectForKey:kArticle]];
    NSLog(@"kArticle = '%@' text = '%@'", kArticle, cell.textLabel.text);
    [mParser.summaryArray removeObject:[mParser.summaryArray objectAtIndex:0]];
    

    【讨论】:

    • 实际上我进行了编辑,当我在几秒钟后不自动滚动标签时会出现问题
    猜你喜欢
    • 2018-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多