Trombone0904
Trombone0904

Reputation: 4258

Why UITableView numberOfRowsInSection is called many times?

I am requesting data from CoreData.

There are two CoreData values.

I have this function to set the numbers of rows:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    print("TEST\n")
    return lebensmittel.count
}

The output of the print is:

TEST

TEST

TEST

TEST

TEST

Why do I get the TEST 5 times when the lebentsmittel.count returns 2?

Upvotes: 1

Views: 1743

Answers (2)

Hari Mohan
Hari Mohan

Reputation: 224

use this code:-

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

remove array element.

Upvotes: 0

Victor Sigler
Victor Sigler

Reputation: 23451

The delegates methods may be called multiple times when your UITableView needs to update anything. By default, it's called very first time the UITableView is loaded or updated (reload data).

It's for this that is not a good practice put anything more inside the numberOfRowsInSection.

I hope this help you.

Upvotes: 2

Related Questions