UIWeb view загружает неправильный адрес из массива

У меня есть приложение, которое заполняет таблицу и выдвигает веб-представление при выделении ячейки. У меня две проблемы

  1. Веб-просмотр загружает и загружает, однако загружаемый веб-адрес неверен. т.е. первая ячейка должна загружать веб-адрес один, но он выглядит случайным. Веб-адреса приходят из массива.

  2. В веб-представлении не отображается первая выбранная ячейка при каждом запуске приложения.

Вот мой код. Любая помощь будет оценена.

Табличное представление

- (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;

}

Подробный вид

- (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];
}

2 ответа

Решение

[webAddress allKeys]; вернусь NSArray но упорядочение не поддерживается в словарях и, следовательно, возвращает случайный массив.

menuItems = [webAddress allKeys];

заменить вышеуказанные коды на отсортированный массив или

menuItems = @[@"one", @"two",...];
Другие вопросы по тегам