Question

First, i have a slide application, there i have a tableview. By tapping a cell "CellInMainMenu" in the main menu, application opens tableview "TV1" by push, and cells in this tableview("TV1") fill with data by an array. When i slide this tableview("TV1") to side, and tapps again on a cell "CellInMainMenu", application opens again tableview("TV1"), but! Tableview("TV1") starts AGAIN to fill cells with information! How to make application load all data by once at starting application?

(I'm really sorry for my English, because it's not my language)

Can somebody help me?

Code in "TV1":

- (void)viewDidLoad    
{    
[super viewDidLoad];
daoDS = [[SampleDataDAO alloc] init];
self.ds = daoDS.PopulateDataSource;    
}

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) 
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}

SampleData *sample = [self.ds objectAtIndex:indexPath.row];
cell.textLabel.text = sample.HeroesName;
cell.textLabel.textColor = [UIColor whiteColor];
cell.textLabel.font = [UIFont fontWithName:@"Trajan-Regular" size:18.0f];

return cell;

}

(All appliction works fine, i just want to know how to make just one load but not every time)

Was it helpful?

Solution

The problem is not your table view code, but how you push it. If you invoke a segue, it will always create a new one.

Instead you could only push it the first time, keep a reference to it and then update it based on a selection of your menu. Some custom delegate @protocol is likely the best pattern for this.

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