UICollection View - Segue - 确实选择了特定的单元格,LOG [英] UICollection View - Segue - did select specific cell , LOG

查看:102
本文介绍了UICollection View - Segue - 确实选择了特定的单元格,LOG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用UICOllectionview来加载自定义制作的相册,相册加载得很好,数据来自我的服务器(SQL-JSON-NSARRAY-NSDictionary)并且填充在单元格中就好了,但是现在我希望当用户选择该单元格来加载一个新的UIVIewController时,该图像的全尺寸(因此他们可以查看/打印/共享等)

I am starting to use a UICOllectionview to load a custom made photo album, the album loads just fine, and the data is coming from my server (SQL-JSON-NSARRAY-NSDictionary) and been populated in the cell's just fine, However now I would like it when the user selects that cell to load a new UIVIewController with that image in full size (so they can view/print/share etc)

但是我陷入'准备segue'的方法,因为我无法从特定的细胞中提取任何信息

However I am getting stuck in the 'prepare for segue' method, as I cannot pull any information from that specific cell

现在作为测试我只想要一个NSLOG说用户选择了标题%@

as a test right now I just want a NSLOG to say "the User selected TITLE OF ALBUM %@ "

到目前为止,这是我的代码,非常感谢任何帮助......

Here is my code thus far, any help would greatly be appreciated...

#import "AlbumViewController.h"
#import "AlbumCustomCell.h"
#import "PhotosInAlbumsViewController.h"

@interface AlbumViewController ()

@end

@implementation AlbumViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    /// Grab Photo Album information (pics,title,date) From Server



    NSString *myURL1 = [ NSString stringWithFormat:         @"http://mywebsiteaddress.com/index.php"];
    NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:myURL1]];
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    NSArray *items = [json objectForKey:@"users"];
    photoalbumarray = items;
   // NSLog(@"%@", photoalbumarray);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;

}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  return [photoalbumarray count];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"CelliD";
    AlbumCustomCell *myCell = (AlbumCustomCell *) [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
    // this above states to setup the cell using the Identifier I specified in Sotry board, so that cell is constantly reused

    if (indexPath.section == 0) { 
         NSDictionary *item = [photoalbumarray objectAtIndex:[indexPath row]];
myCell.titleincell.text = [item objectForKey:@"title"]; // this puts the title in the cell
        teststring = [item objectForKey:@"title"];

        myCell.dateincell.text = [item objectForKey:@"date"]; // this puts the date in the     data label in the cell


      //  myCell.imageincell1.image = [UIImage imageNamed:[item objectForKey:@"img1"]]; // this puts the picture in the cell
         myCell.imageincell2.image = [UIImage imageNamed:[item objectForKey:@"img2"]]; // this puts the picture in the cell
         myCell.imageincell3.image = [UIImage imageNamed:[item objectForKey:@"img3"]]; // this puts the picture in the cell

        // IMAGE 1
        NSString *picture1 = [item objectForKey:@"img1"];
        NSURL *imageURL1 = [NSURL URLWithString:picture1];
        NSData * imageData1 = [NSData dataWithContentsOfURL:imageURL1];
        UIImage * image1 = [UIImage imageWithData:imageData1];
        myCell.imageincell1.image = image1;

    myCell.imageincell1.alpha = 0.0;
    [UIView animateWithDuration:1.5 animations:^{
        myCell.imageincell1.alpha = 1.0;
    }];


    // IMAGE 2
    NSString *picture2 = [item objectForKey:@"img2"];
    NSURL *imageURL2 = [NSURL URLWithString:picture2];
    NSData * imageData2 = [NSData dataWithContentsOfURL:imageURL2];
    UIImage * image2 = [UIImage imageWithData:imageData2];
    myCell.imageincell2.image = image2;

    myCell.imageincell2.alpha = 0.0;
    [UIView animateWithDuration:1.5 animations:^{
        myCell.imageincell2.alpha = 1.0;
    }];



    // I MAGE 3
    NSString *picture3 = [item objectForKey:@"img3"];
    NSURL *imageURL3 = [NSURL URLWithString:picture3];
    NSData * imageData3 = [NSData dataWithContentsOfURL:imageURL3];
    UIImage * image3 = [UIImage imageWithData:imageData3];
    myCell.imageincell3.image = image3;
    myCell.imageincell3.alpha = 0.0;
    [UIView animateWithDuration:1.5 animations:^{
        myCell.imageincell3.alpha = 1.0;
    }];

}
return myCell;
}



// SEGUE TRANSITION FROM ALBUMS TO PHOTO
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showPhotoAlbum"]) {
        NSLog(@"Prepare for Segue to load Specific Photo Album");
        NSLog(@"User Selected this cell or the name of the title in the cell which comes from a NSDictionary =>");
// EXAMPLE NSLOG TO SHOW =>  User Selected - Album Name
// Where album name is actually the album name grabbed form the server based on the selected row
    }
}

@end

这样你就可以看到来自服务器的JSON数据,这里是

and just so you can see my JSON data from the server coming in, here that is

2012-10-01 13:02:53.856 CB Photo[3957:907] (
        {
        date = "2012-10-01 07:23:01";
        id = 1;
        img1 = "http://b2fdev.ca/demo/CBPhoto/pic1.jpg";
        img2 = "http://b2fdev.ca/demo/CBPhoto/pic2.jpg";
        img3 = "http://b2fdev.ca/demo/CBPhoto/pic3.jpg";
        title = "Paul and Jenna's Wedding 2012";
    },
        {
        date = "2012-10-01 05:23:23";
        id = 2;
        img1 = "http://core1.ca/wp-content/themes/custom-community/images/block4.png";
        img2 = "http://core1.ca/wp-content/themes/custom-community/images/block3.png";
        img3 = "http://core1.ca/wp-content/themes/custom-community/images/block2.png";
        title = "Core 1";
    }
)


推荐答案

你是这个吗?

NSArray *indexPaths = [self.collectionView indexPathsForSelectedItems];
DetailViewController *destViewController = segue.destinationViewController;

NSIndexPath *index = [indexPaths objectAtIndex:0];

NSLog(@"%d", index.section * 2 + index.row);

这个打印索引的数组为2 x无论数组;

this print index in array in 2 x whatever array;

这篇关于UICollection View - Segue - 确实选择了特定的单元格,LOG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆