2011-06-24 50 views
0

我當前的應用程序由導航與選項卡組成,然後是Table View之間的表格視圖,當選擇了Detail View時,該表格將被推送。我遇到的問題是,當我選擇一行時,它將推送到詳細信息視圖並在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]]]; 
} 
} 

回答

0

既然你保留的ATextController實例和重用它,你將不得不執行在viewWillAppear:之後的片段 -

原因是當視圖控制器加載其視圖時調用viewDidLoad。每當視圖即將出現在屏幕上時,將調用viewWillAppear:

+0

非常感謝。我會牢記這一點。 – xTHENKx