从表视图中推送时,Web视图不会更新

时间:2011-06-24 00:41:52

标签: objective-c uitableview ios4 uiwebview uinavigationbar

我当前的应用程序包括使用选项卡导航,然后选择介于两者之间的表格视图,从表格行中选择按下详细信息视图。我遇到的问题是,当我选择一行时,它会推送到详细信息视图并在Web视图中加载html文件。但是,当我向后导航然后选择另一行时,它会从前一个选择中加载相同的html。唯一保持相关性的是导航标题栏中的标题。

这对我来说是不好的记忆管理(我是ObjC的新手......就像一周一样)还是我错过了一步?我想我抓住了NSString * navDate = self.title;是我的问题。其他一切基本上都是有效的。无论如何,要温柔,谢谢。 :$

表格单元

- (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;
}

行推

(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]]];
}
}

1 个答案:

答案 0 :(得分:0)

由于您要保留ATextController的实例并重复使用,因此您必须在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]]];
}

原因是视图控制器加载视图时调用viewDidLoad一次。每次视图即将出现在屏幕上时,都会调用viewWillAppear: