I have a tabBar application that has ResultsNavController as 1 of my tabBar's Nav Controller, the View Controller is ResultsViewController and my tableViewPtr is connected to the tableView in IB which is under Main window.xib ResultsNavController/ResultsViewController/View/tableView.
After going to another tab to write to PureFun.plist, clicking on results view doesn't reload the table instantly with the new PureFun.plist. PureFun.plist was successfully written after i checked.
- (void)viewWillAppear:(BOOL)animated {
[self.tableViewPtr reloadData];
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [resultsDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"ResultsCellIdentifier";
UILabel *scoreStrLabel;
UILabel *dateStrLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
dateStrLabel = [[[UILabel alloc] initWithFrame:CGRectMake(10,5.0,200,43)] autorelease];
dateStrLabel.tag = DATESTR_TAG;
dateStrLabel.font = [UIFont systemFontOfSize:18.0];
dateStrLabel.textAlignment = UITextAlignmentLeft;
dateStrLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:dateStrLabel];
scoreStrLabel = [[[UILabel alloc] initWithFrame:CGRectMake(250,5.0,50,43)] autorelease];
scoreStrLabel.tag = SCORESTR_TAG;
scoreStrLabel.font = [UIFont systemFontOfSize:18.0];
scoreStrLabel.textAlignment = UITextAlignmentRight;
scoreStrLabel.textColor = [UIColor blackColor];
[cell.contentView addSubview:scoreStrLabel];
}
else {
scoreStrLabel = (UILabel *)[cell.contentView viewWithTag:SCORESTR_TAG];
dateStrLabel = (UILabel *)[cell.contentView viewWithTag:DATESTR_TAG];
}
NSDictionary *dict = [resultsDataArray objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat:@"h':'mma, EEE d MMM"];
NSDate *dateTested = [dict objectForKey:@"Date"];
NSString *dateStr = [formatter stringFromDate:dateTested];
NSString *scoreStr = [dict objectForKey:@"Score"];
scoreStrLabel.text = scoreStr;
dateStrLabel.text = dateStr;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 49.1;
}
- (void)viewDidLoad {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *myPathDocs = [documentsDirectory stringByAppendingPathComponent:@"PureFun.plist"];
NSArray *array = [[NSArray alloc] initWithContentsOfFile:myPathDocs];
self.resultsDataArray = array;
[array release];
[super viewDidLoad];
}