web view not updating when pushed from table view
My current app consists of Navigation with Tabs, then a Table View in between, from the Table Rows when selected a Detail View is pushed. The issue I'm having is when I select a row it pushes to the Detail View and loads the html file in the Web View. However, when I navigate back and then select another row, it loads the same html from the pr开发者_开发百科evious selection. The only thing that stays relevant is the Title in the Navigation Title Bar.
Is this poor memory management on my part (I'm new to ObjC.. like only a week) or did I miss a step? I think me grabbing NSString *navDate = self.title; is my problem. Everything else basically works otherwise. Anyways, be gentle and thanks. :$
Table Cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if(cell == nil){
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellID];
}
cell.textLabel.font = [UIFont systemFontOfSize:15];
cell.textLabel.text = [self.dateList objectAtIndex: [indexPath row]];
return cell;
}
Row Push
(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if(self.aTextController == nil){
ATextController *aTextDetail = [[ATextController alloc] initWithNibName:@"ArchiveData" bundle:nil];
self.aTextController = aTextDetail;
[aTextDetail release];
}
aTextController.title = [NSString stringWithFormat:@"%@", [dateList objectAtIndex:row]];
SLESDAppDelegate *delegate = (SLESDAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.navigationController pushViewController:aTextController animated:YES];
}
DetailView
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *navDate = self.title;
NSString *null = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", navDate] ofType:@"html"];
if(null != nil){
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", navDate] ofType:@"html"]isDirectory:NO]]]; }
else {
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]isDirectory:NO]]];
}
}
Since you are retaining the instance of ATextController
and reusing it, you will have to execute the following snippet in viewWillAppear:
-
NSString *navDate = self.title;
NSString *null = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", navDate] ofType:@"html"];
if(null != nil){
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@", navDate] ofType:@"html"]isDirectory:NO]]]; }
else {
[webArchView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"error" ofType:@"html"]isDirectory:NO]]];
}
The reason being that viewDidLoad
is called once when the view controller loads its view. viewWillAppear:
will be called every time the view is about to come on screen.
精彩评论