2012-04-11 49 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

相关问题