Я использую Collection view, у меня есть 6 ячеек в коллективном представлении, и я хочу представить разные URL-адреса на клике, как я могу это сделать? с помощью массива URL-адресов? или есть другой способ сделать это?web view not loading url
FirstViewController.m
-(void)viewDidLoad{
array=[NSArray arrayWithObjects:@"home.jpg",@"about-us.png",@"aarti.png",@"video.png",@"news.png",@"contact.png", nil];
NSString *[email protected]"url1";
NSString *[email protected]"url2";
NSString *[email protected]"url3";
NSString *[email protected]"url4";
NSString *[email protected]"url5";
NSString *[email protected]"url6";
urls=[NSArray arrayWithObjects:url1,url2,url3,url4,url5,url6, nil];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return array.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"collect";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[array objectAtIndex:indexPath.row]];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSString *urlAddress = [urls objectAtIndex:indexPath.row];//url at clicked index from array
NSURL *url = [NSURL URLWithString:urlAddress];
WebViewController *webView=[[WebViewController alloc]init];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView.webview loadRequest:requestObj];
}
чтения о любой структуре MVC или CollectionView учебник – Shubhank
@Shubhank да я есть создать представление коллекции, имеющий 6 ячеек, и теперь я хочу представить 6 URLs на веб-просмотра, я создал веб-просмотра и успешно представляя и URL, но я не знаю, как представить разные URL-адреса, с учетом индекса ячейки. –
есть метод делегата коллекции 'didSelectItemAtIndexPath' здесь вы можете получить URL-адрес позиции и показать ее в веб-просмотре или передать в любом случае, что хотите. – Shubhank