Howard Spear
Howard Spear

Reputation: 551

UITableView cellForRowAtIndexPath invoked multiple times if it's a manual call?

If I have UITableView as a property of a UIViewController and I'm manually accessing a cell at a particular row with [tableView cellForRowAtIndexPath:indexPath].

On one method invoke, should I expect to see multiple calls to:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Each of my UITableViewCell has a UITextField whose text data I'm trying to access.

Here's what I'm doing:

for (int section = 0; ix < countOfSections; ++section)
{
    NSInteger countOfRowsInSection = // attained
    for (int row = 0; row < countOfRowsInSection; ++row)
    {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];

        // the follow call seems to elicit multiple invocations 
        // on my table delegate's
        // - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

        UITableViewCell *cell = [self.tableview cellForRowAtIndexPath:indexPath];

        // Access some custom data
    }
}

Is there a better way to access all of the data stored in the UITextField each of the UITableViewCell for all sections & rows?

Upvotes: 0

Views: 984

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31016

You really shouldn't be trying to use views for data storage. In whatever you're using as the table's data source there should be an array (or other structure) of objects that contains the data that provides content for the cells when tableView:cellForRowAtIndexPath: is called.

If you need other access to that information, you should be getting it directly from the data structure rather than the display.

Upvotes: 1

Related Questions