1
我有一个由存储被初始化在NSMutableArray的项目如下从Web服务解析XML的程序:NSMutableArray的初始化仅一次
- (id)init {
self = [super init];
if (self)
{
items = [[NSMutableArray alloc] init];
}
return self;
}
我用滚动型委托检查时,用户点击的tableview的底部,其中我打电话给Web服务的另一个页面加载已获取项目底部的更多项目。
但是,当tableview重新加载时,它不会在已经提取的底部添加新项目,而只会出现新项目。
在我可以设置insertrowsatindexpaths与动画之前,我相信NSMutableArray再次被初始化,使旧的条目消失,只显示新的。我如何使NSMutableArray只初始化一次,所以当它获得新的条目时,它会将它们加载到已获取的可变数组中。
编辑
根据该意见,看起来像我这样做精与MutableArray及其得到初始化一次。然后,数据源一定有问题。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[channelFeed items] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ItemsViewCell *cell = (ItemsViewCell *)[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (cell == nil) {
cell = [[ItemsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
FeedItem *item = [[channelFeed items] objectAtIndex:[indexPath row]];
cell.titleLabel.text = [item title];
cell.pubDateLabel.text = [item pubDate];
cell.creatorLabel.text = [item creator];
[[cell thumbImage] setImage:[item thumbnail]];
return cell;
}
看起来没问题。你可以发布你如何添加项目? – yinkou
我认为你应该显示更多的代码 –
该数组仅在初始化viewcontroller时分配,因此可能只有一次。 plz添加代码,将项目插入数组 –