gpt4 book ai didi

ios - 未通过第一个 View Controller 接收 UIImage

转载 作者:行者123 更新时间:2023-11-28 21:27:33 24 4
gpt4 key购买 nike

您好,我目前只是“认为我已经通过 prepare for segue 破解了发送内容”,但问题是我的图像没有显示在第二个 View Controller 中。因为我是新手,所以我想知道我是否遗漏了什么,因为无论如何我似乎都无法让我的第一个 View Controller 的图像显示在我的第二个 View Controller 中。

GroupsViewController.h

#import <UIKit/UIKit.h>
@interface GroupsViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *GroupsCollectionView;

- (IBAction)cellToggleAction:(id)sender;

@end

GroupsViewController.m

#import "GroupsViewController.h"
#import "GroupsHomeViewController.h"
#import "CustomCell.h"


@interface GroupsViewController ()
{
NSArray *arrayOfImages;
NSArray *arrayOfDescriptions;
}

@end

@implementation GroupsViewController
{
NSString *reuseIdentifier;
}

- (void)viewDidLoad
{
[super viewDidLoad];
[[self GroupsCollectionView]setDataSource:self];
[[self GroupsCollectionView]setDelegate:self];
reuseIdentifier= @"SmallIcon"; //set inital value of reuse identifier

arrayOfImages = [[NSArray alloc]initWithObjects:@"a.png", nil];

arrayOfDescriptions = [[NSArray alloc]initWithObjects:@"A", nil];
}

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

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

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
[[cell IconImage]setImage:[UIImage imageNamed:[arrayOfImages objectAtIndex:indexPath.item]]];
[[cell IconLabel]setText:[arrayOfDescriptions objectAtIndex:indexPath.item]];
return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"GroupsHomeSegue" sender:indexPath];
}

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

if ([segue.identifier isEqualToString:@"GroupsHomeSegue"])
{
NSIndexPath* indexPath = [[self.GroupsCollectionView indexPathsForSelectedItems]firstObject];
if(indexPath !=nil)
{
//NSString *selectedDescription = arrayOfDescriptions[indexPath.item]; //collects description from cell
NSString *selectedImage = arrayOfImages [indexPath.item]; //collects image from cell

GroupsHomeViewController *groupsHomeViewController = segue.destinationViewController;
groupsHomeViewController.logoImage = [UIImage imageNamed: selectedImage];
//groupsHomeViewController.groupLabel = [:selectedDescription];

}
}
}


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

@end

GroupsHomeViewController.h

#import <UIKit/UIKit.h>

@interface GroupsHomeViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>

@property (strong, nonatomic) IBOutlet UIImage *logoImage;
@property (strong, nonatomic) IBOutlet UILabel *groupLabel;

@end

GroupsHomeViewController.m

#import "GroupsHomeViewController.h"

@interface GroupsHomeViewController ()

@end

@implementation GroupsHomeViewController

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

@end

提前感谢您的帮助。

最佳答案

李苏格登,

传递图像是不够的:) 如果你想让它显示在你的屏幕上,你应该将它加载到 ImageView 中,不是吗:)

现在要么以编程方式创建 UIImageView,要么在 Storyboard中添加一个 imageView 绘制一个 IBOutlet 并将图像设置为

self.yourImageView.image = self.logoImage;

否则以编程方式创建一个 UIImageView,

UIImageView *yourImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,self.logoImage.size.width,self.logoImage.size.height)];
yourImageView.image = self.logoImage;
[self.view addSubview:yourImageView];

关于ios - 未通过第一个 View Controller 接收 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37470384/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com