Question

I have a program that parses xml from the web service by storing items in NSMutableArray which is initialised as follows:

- (id)init {

    self = [super init];
    if (self)
    {
        items = [[NSMutableArray alloc] init];
    }
    return self;
}

I have used ScrollView delegate to check when user hits the bottom of tableview, in which i am calling another page of the web service to load more items at the bottom of already fetched items.

But when the tableview is reloaded, it does not add new items at the bottom of already fetched ones, instead it only the new ones appears.

Before i can set insertrowsatindexpaths with animation, i believe NSMutableArray is getting initialised again that is making the old entries disappear and showing the new ones only. How i can make the NSMutableArray initialise only once so when it gets the new entries, it loads them after the already fetched ones in the mutable array.

EDIT

According to the comments, looks like i am doing fine with the MutableArray and its getting initialised only once. Then there must be something wrong with the data source.

- (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;
}
Was it helpful?

Solution

I would initialize the array in a more convinient place. Apparently, your code calls the init, which will reinitialize the array and delete its contents.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top