我有一个包含很多项目的表格视图,当我单击表格中的一个单元格时,它会加载一个带有 web 视图插座的视图,在 viewdidload 的 web 视图中,我有这行代码来加载 html 文件,它位于项目文件
NSString *name = pagename.text;
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:name ofType:@"html"]isDirectory:NO]]];
从所选单元格推送到该 Web 视图的代码称为 Test 是
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];
}
}