首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIWeb视图从数组加载错误地址

UIWeb视图从数组加载错误地址
EN

Stack Overflow用户
提问于 2013-09-25 03:08:19
回答 2查看 63关注 0票数 0

我有一个应用程序,可以填充表格,并在选定的单元格中推送web视图。我有两个问题

  1. 然而,web视图推送和加载加载的web地址是不正确的。也就是说,第一个单元应该加载一个web地址,但它似乎是随机的。网络地址来自一个数组。
  2. 每次启动应用程序时,web视图都不会按下所选择的第一个单元格。

这是我的密码。任何帮助都是必要的。

表视图

代码语言:javascript
复制
- (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;

}

细节视图

代码语言:javascript
复制
- (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];
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-09-25 04:10:26

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

票数 1
EN

Stack Overflow用户

发布于 2013-09-25 06:25:50

代码语言:javascript
复制
menuItems = [webAddress allKeys];

将上述代码替换为排序数组或

代码语言:javascript
复制
menuItems = @[@"one", @"two",...];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18995536

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档