gpt4 book ai didi

ios - UIWeb View 从数组加载错误的地址

转载 作者:行者123 更新时间:2023-11-29 03:37:18 26 4
gpt4 key购买 nike

我有一个应用程序可以填充表格并在选中单元格时推送 WebView 。我有两个问题

  1. Web View 推送和加载,但加载的网址不正确。即第一个单元格应该加载一个网址,但它似乎是随机的。网址来自一个数组。

  2. Web View 不会在每次启动应用时推送到选定的第一个单元格。

这是我的代码。如有任何帮助,我们将不胜感激。

表格 View

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}

- (void)viewDidLoad {

[self setupArray];
[super viewDidLoad];
// Do any additional setup after loading the view.
}

-(void)setupArray {
webAddress = [[NSMutableDictionary alloc]init];
[webAddress setObject:@"http://www.google.com.au" forKey:@"one"];
[webAddress setObject:@"http://www.finddrinkdine.com.au" forKey:@"Two"];
[webAddress setObject:@"http://www.kingsgroversl.com.au" forKey:@""three"];
[webAddress setObject:@"http://www.yahoo.com.au" forKey:@"Four"];
[webAddress setObject:@"http://www.scu.edu.au" forKey:@"Five"];
[webAddress setObject:@"http://www.whitenow.com.au" forKey:@"Six"];

menuItems = [webAddress allKeys];

}

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

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}

cell.textLabel.text = [menuItems objectAtIndex:indexPath.row];
return cell;

}

详细 View

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
return self;
}

-(void)viewWillAppear:(BOOL)animated {
NSURL *url = [NSURL URLWithString:webAddress];
NSURLRequest *req = [NSURLRequest requestWithURL:url];
[viewWeb loadRequest:req];

[super viewWillAppear:animated];
}

最佳答案

[webAddress allKeys];将返回 NSArray ,但字典中不维护排序,因此它返回随机数组。

关于ios - UIWeb View 从数组加载错误的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18995536/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com