2012-04-11 58 views
0

我有一個表格視圖,其中有很多項目 當我點擊表格中的一個單元格時,它在web view中加載了一個視圖,在viewdidload中的web視圖中我有這個行代碼來加載HTML文件至極是在項目文件將html文件加載到網頁視圖

NSString *name = pagename.text; 
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"html"]isDirectory:NO]]]; 

從選定單元格與被稱爲測試的是Web視圖推代碼

if (indexPath.row == 0) 
{ 

    Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
    test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:test animated:YES]; 

    NSString *name1 = @"ba"; 
    [[test pagename] setText:[NSString stringWithString:(NSString *)name1]]; 

} 

else if (indexPath.row == 1) 
{ 

    Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
    test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:test animated:YES]; 

    NSString *name1 = @"bb"; 
    [[test pagename] setText:[NSString stringWithString:(NSString *)name1]]; 

} 

else if (indexPath.row == 2) 
{ 

    Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
    test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    [self presentModalViewController:test animated:YES]; 

    NSString *name1 = @"bc"; 
    [[test pagename] setText:[NSString stringWithString:(NSString *)name1]]; 

} 

的HTML文件被稱爲ba,bb,bc和bd .html

問題是當我選擇表格中的四個單元格中的任意一個單元格時,它顯示相同的html文件「ba.html」

我試過了一切,清理項目,刪除文件並將其複製回來,改變了模擬器,重新啓動了圈,甚至改變了文件名。

有幫助嗎?

在此先感謝

更新:

這是孔代碼

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [array count]; 
} 


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"CustomCell"; 


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

    [[cell textLabel] setTextAlignment:UITextAlignmentRight]; 

    cell.textLabel.text = [array objectAtIndex:indexPath.row]; 
    cell.textLabel.font = [UIFont systemFontOfSize:18]; 
    cell.textLabel.numberOfLines = 3; 

    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    if (indexPath.row == 0) 
    { 

     Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
     test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:test animated:YES]; 

     NSString *name1 = @"ba"; 
     [[test pagename] setText:name1]; 

    } 

    else if (indexPath.row == 1) 
    { 

     Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
     test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:test animated:YES]; 

     NSString *name1 = @"bb"; 
     [[test pagename] setText:name1];   
    } 

    else if (indexPath.row == 2) 
    { 

     Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
     test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:test animated:YES]; 

     NSString *name1 = @"bc"; 
     [[test pagename] setText:name1]; 
    } 

    else if (indexPath.row == 3) 
    { 

     Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
     test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     [self presentModalViewController:test animated:YES]; 

     NSString *name1 = @"bd"; 
     [[test pagename] setText:name1]; 

    } 
} 

回答

1

設置頁面之前,您正在演示控制器。

在您的webview類中將'name'設爲NSString實例變量。使它成爲一個屬性(非原子,保留)併合成它。

而不是設置viewcontroller的標籤,設置名稱。 然後在viewDidLoad中,從名稱中設置標籤。

從名稱中設置標籤,而不是反過來。

在電池選擇:

Test *test = [[Test alloc] initWithNibName:nil bundle:nil]; 
test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
NSString *name1 = @"bc"; 
[test setName:[NSString stringWithString:(NSString *)name1]]; 
[self presentModalViewController:test animated:YES]; 

在Web視圖viewDidLoad中

-(void)viewDidLoad { 
    pagename.text = self.name; 
    [WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"html"]isDirectory:NO]]]; 
} 
+0

我添加了編碼@PRNDL Development Studios – aLFaRSi 2012-04-11 18:01:44

+0

編輯。試試看。 – 2012-04-11 18:18:32

+0

仍然一樣,沒有任何變化 – aLFaRSi 2012-04-11 18:22:58

0

你可以把一個斷點或日誌,看是否indexPath.row始終爲0?

如果是這種情況,那麼您的表格可能是以每個元素都在其自己的部分中的方式創建的。然後你必須使用indexPath.section,因爲每個對象都是它自己部分的第0行。

另外,我不知道哪個對象的類型是「頁面名稱」,但制定者通常保留參數,所以你不必在

[[test pagename] setText:[NSString stringWithString:(NSString *)name1]]; 

注創建名1的副本:這真的取決於如何在類中聲明屬性,但通常保留這些類型的屬性。

+0

我的表是在IB中創建的,拖動一個表視圖,將它鏈接到委託並將其稱爲TableView並將其鏈接到文件所有者,我嘗試了.section == 0,並且它與我記錄的.row和它相同的 – aLFaRSi 2012-04-11 18:06:21

+0

.section都給出了正確的數字,0,1,2,..... – aLFaRSi 2012-04-11 18:11:35