我试图连接表格视图中的每个单元格必须与Web视图中的不同网页连接,我还使用了导航控制器。
这是maincontroller.m文件
`-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.settle count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
static NSString *simpletableidentifier = @"tcell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpletableidentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpletableidentifier];
}
cell.textLabel.text = [settle objectAtIndex:indexPath.row];
return cell;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"show"]) {
NSIndexPath *indexPath=self.tableView.indexPathForSelectedRow;
website *destViewController = segue.destinationViewController;
destViewController.web = [settle objectAtIndex:indexPath.row];
switch (indexPath.row) {
case 0:
destViewController.u=@"http//www.google.com";
break;
case 1:
destViewController.u=@"http//www.yahoo.com";
break;
default:
break;
}
}
`
并在另一个视图控制器文件中
@implementation website
@synthesize web;
@synthesize u;
//@synthesize recipeLabel;
//@synthesize recipeName;
- (void)viewDidLoad
{
[super viewDidLoad];
// Add code to load web content in UIWebView
{
NSURL *url = [NSURL URLWithString:@"u"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[web loadRequest:request];
}
答案 0 :(得分:0)
首先,您不需要为每个单元格创建单独的UIWebview对象。 单个Webview可用于加载不同的URL。
为了解决你的问题 在viewDidLoad方法中,正确创建url对象
(void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:self.u];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[web loadRequest:request];
}
并提供正确的网址格式,例如@"http://www.google.com/
。