Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iOS 6集合视图控制器多个动态单元_Iphone_Xcode_Uicollectionviewcell_Collectionview - Fatal编程技术网

Iphone iOS 6集合视图控制器多个动态单元

Iphone iOS 6集合视图控制器多个动态单元,iphone,xcode,uicollectionviewcell,collectionview,Iphone,Xcode,Uicollectionviewcell,Collectionview,我只进入Xcode一周,试图学习一些东西,这样我就可以为一个项目做出贡献 到目前为止,我一直在研究教程,并取得了一些成果:)但我还远远没有结束。我希望有人能理解我的要求 我正在制作一个应用程序,它将从服务器获取数据,数据将包括缩略图、图像和文本。现在,我有一个集合视图控制器,其中一个单元格有3个按钮(我发现它们更容易放在集合视图单元格中),按钮的背景是一个特定的图像(目前已硬编码),它会将您带到一个视图控制器,其中显示该项目的所有内容,没有什么特别之处:) 但是布局(设计)对我来说很难实现。基本

我只进入Xcode一周,试图学习一些东西,这样我就可以为一个项目做出贡献

到目前为止,我一直在研究教程,并取得了一些成果:)但我还远远没有结束。我希望有人能理解我的要求

我正在制作一个应用程序,它将从服务器获取数据,数据将包括缩略图、图像和文本。现在,我有一个集合视图控制器,其中一个单元格有3个按钮(我发现它们更容易放在集合视图单元格中),按钮的背景是一个特定的图像(目前已硬编码),它会将您带到一个视图控制器,其中显示该项目的所有内容,没有什么特别之处:)

但是布局(设计)对我来说很难实现。基本上(根据我的理解),我需要有4个集合视图单元格,带有不同位置的按钮。现在我有了一个集合视图控制器,其中有一个集合视图,包含一个单元格

#import "CollectionViewController.h"
#import "CollectionViewCell.h"
#import "ImageDetailsViewController.h"
#import "StoryItem.h"

@interface CollectionViewController ()
{
    NSArray *arrBigLeft;
    NSArray *arrSmallTopR;
    NSArray *arrSmallBotR;
}

@end

@implementation CollectionViewController

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

- (void)viewDidLoad
{


    arrBigLeft = [[NSArray alloc]initWithObjects:@"imageicon0@2x.jpg", @"imageicon1@2x.jpg", @"imageicon2@2x.jpg", @"imageicon3@2x.jpg", nil];

    arrSmallTopR = [[NSArray alloc]initWithObjects:@"imageicon4@2x.jpg", @"imageicon5@2x.jpg", @"imageicon6@2x.jpg", @"imageicon7@2x.jpg", nil];

    arrSmallBotR = [[NSArray alloc]initWithObjects:@"imageicon8@2x.jpg", @"imageicon9@2x.jpg", @"imageicon0@2x.jpg", @"imageicon1@2x.jpg", nil];

    [super viewDidLoad];

    // Do any additional setup after loading the view.
}

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

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if([segue.identifier isEqualToString:@"photoDetail1"]){
        CollectionViewCell *cell = (CollectionViewCell *)sender;
        NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];

        ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
        idvc.img = [UIImage imageNamed:[arrBigLeft objectAtIndex:indexPath.item]];

    }


    if([segue.identifier isEqualToString:@"photoDetail2"]){
        CollectionViewCell *cell = (CollectionViewCell *)sender;
        NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];

        ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
        idvc.img = [UIImage imageNamed:[arrSmallTopR objectAtIndex:indexPath.item]];

    }


    if([segue.identifier isEqualToString:@"photoDetail3"]){
        CollectionViewCell *cell = (CollectionViewCell *)sender;
        NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell];
                ImageDetailsViewController *idvc = (ImageDetailsViewController *)[segue destinationViewController];
        idvc.img = [UIImage imageNamed:[arrSmallBotR objectAtIndex:indexPath.item]];

    }
}

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



// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *identifier=@"Cell";

    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    [[cell button1]setBackgroundImage:[UIImage imageNamed:[arrBigLeft objectAtIndex:indexPath.item]] forState:UIControlStateNormal];

    [[cell button2]setBackgroundImage:[UIImage imageNamed:[arrSmallTopR objectAtIndex:indexPath.item]] forState:UIControlStateNormal];

    [[cell button3]setBackgroundImage:[UIImage imageNamed:[arrSmallBotR objectAtIndex:indexPath.item]] forState:UIControlStateNormal];

    return cell;
}


-(IBAction)returned:(UIStoryboardSegue *)segue {

}



@end
这还没有达到我想要的效果,但至少我得到了动态创建的单元格。我希望能够返回多个单元格,包含不同的项目(图像)数组,并且它们都应该同时加载

在这里,你只能看到两个单元格,但我添加的第二个单元格只是为了可视化我试图解释的内容(4个不同的单元格) 当我运行应用程序时,第一个单元格(因为图像的数量)重复4次,如果我要将相同的图像添加到第二个单元格,我希望看到它们与屏幕截图中的相同,并继续按照与图像数量相同的顺序重复(数组的长度)


如果您需要更多代码,请告诉我。。谢谢

我建议遵循这一点,以便对所需内容有一个基本的了解


这样您就可以进行更复杂的设计。看起来像是你跳进了深渊。但是本教程非常好。

感谢您的教程,我可以看到您可以使用collectionView做很多事情。。我会好好检查一下:)是的,你可以做一些很酷的事情。如果您对答案满意,请标记为正确。