- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我还没有找到解决这个问题的方法。我已将视频附加到我的应用程序以查看其运行情况。
问题发布在正在发生的事情和应该发生的事情的底部。
https://www.mediacloud.cc/a/public/85156c9d4867ec82a42002e21954ee70.php?lang=en
我正在使用单例方法在我的两个 View Controller 之间传递数据,因为它们没有直接连接。
我正在使用的 4 个相关类是 MyAppDelegate、CameraViewController、TableViewController 和 CaptureSession。
我的 appDelegate.h 类
@property (nonatomic, retain) NSMutableArray *emailProperty;
@property (nonatomic, retain) NSMutableArray *imageProperty;
@property (nonatomic, retain) NSMutableDictionary *dictionaryProperty;
@property (nonatomic, retain) NSString *emailStringProperty;
@property (nonatomic, retain) UIImage *assetImageProperty;
@property (nonatomic, retain) UIImage *captureImageProperty;
+ (id)sharedManager;
我的 appDelegate.m 类
@synthesize emailProperty;
@synthesize imageProperty;
@synthesize dictionaryProperty;
@synthesize emailStringProperty;
@synthesize assetImageProperty;
@synthesize captureImageProperty;
#pragma mark Singleton Methods
+ (id)sharedManager {
static MediaCloudAppDelegate *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init {
if (self = [super init]) {
emailProperty = [NSMutableArray array];
imageProperty = [NSMutableArray array];
dictionaryProperty = [NSMutableDictionary dictionary];
}
return self;
}
CameraViewController.m 类
当用户在 CameraViewController 中时,他在触摸事件后立即按下“拍照”,弹出 UIalertview 要求他输入他的电子邮件。这是处理用户输入的代码。
_emailString1 = [alertView textFieldAtIndex:0].text;
MediaCloudAppDelegate *sharedManager = [MediaCloudAppDelegate sharedManager];
sharedManager.emailStringProperty = _emailString1;
[sharedManager.emailProperty addObject:sharedManager.emailStringProperty];
用户输入电子邮件并单击“确定”后,他们现在可以拍照了。
因为我正在使用 AVCapturesSession 来拍照。这是代码。
CaptureSession.m 类
NSData *imageData = [AVCaptureStillImageOutput
jpegStillImageNSDataRepresentation:imageSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self setStillImage:image];
MediaCloudAppDelegate *sharedManager = [MediaCloudAppDelegate sharedManager];
sharedManager.captureImageProperty = image;
[sharedManager.dictionaryProperty setObject:sharedManager.captureImageProperty
forKey:sharedManager.emailStringProperty];
[sharedManager.imageProperty addObject:sharedManager.dictionaryProperty];
NSLog(@"image %@", sharedManager.imageProperty);
拍照后,我记录输出。
例如。假设用户电子邮件是 bob@email.com 并拍了一张他自己的照片。
My NSLog(@"image %@", sharedManager.imageProperty);是图片
{
bob@email.com = "UIImage: 0x1568d8c0";
}
现在要显示应用程序拍摄的所有照片和电子邮件,我们转到 TableViewController。
TableViewController.m 类
我的 TableView 设计是这样的。在一个单元格中,我有一个 UICollectionView,在右边我有一个 UILabel。
我这样显示电子邮件数组。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
MediaCloudAppDelegate *sharedManager = [MediaCloudAppDelegate sharedManager];
// Return the number of rows in the section.
return sharedManager.emailProperty.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
static NSString *CellIdentifier = @"Cell";
EmailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
MediaCloudAppDelegate *sharedManager = [MediaCloudAppDelegate sharedManager];
cell.emailLabel.text = [sharedManager.emailProperty objectAtIndex:indexPath.row];
return cell;
}
为了在单元格内的 Collection View 中显示照片,我这样做了。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier
forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
MediaCloudAppDelegate *sharedManager = [MediaCloudAppDelegate sharedManager];
sharedManager.dictionaryProperty = [sharedManager.imageProperty objectAtIndex:indexPath.row];
imageView.image = [sharedManager.dictionaryProperty
objectForKey:sharedManager.emailStringProperty];
return cell;
}
现在一切正常,唯一的问题是每个单元格中的每个 Collection View 显示整个照片数组,而不是与唯一电子邮件字符串关联的照片。
所以如果我有行。
第一行是鲍勃第 2 行是杰夫第 3 行是戴夫
我们有每个人的照片。 Bob 行中的 Collection View 应该只显示 Bob 的照片。而 Jeff 行中的 Collection View 应该只显示 Jeff 等的照片。现在的问题是。 Bob 所在行的 Collection View 显示了所有三个人的照片,其他两个人的照片也是如此。
而且我不知道如何让它发挥作用。
提前感谢您的帮助!
最佳答案
您应该将要在每个 tableView 单元格中显示的图像存储为一个数组,然后将该数组传递给一个单独的 collectionView 实例。您不能只使用一个数组来存储所有图像并期望各种 collectionViews 挑选并选择要显示的图像。 (好吧,你可以,但要难得多)
在 cellForRowAtIndexPath
中传递信息的方式将取决于自定义 Cell 对象的组织方式。
实现此目的的一种方法是将每个数组存储在字典中,以用户电子邮件为键。另一种方法是将所有数组存储在另一个主数组中,由 indexPath.row 索引。
如果不清楚,请告诉我。因此,当您捕获图像时,将其添加到一个数组并将其存储在一个数组中,然后将其添加到您的字典中:
sharedManager.captureImageProperty = image;
NSMutableArray *array = sharedManager.dictionaryProperty[sharedManager.emailStringProperty];
if (!array) array = [NSMutableArray new];
[array addObject: sharedManager.captureImageProperty];
[sharedManager.dictionaryProperty setObject:array
forKey:sharedManager.emailStringProperty];
然后从字典中取出数组并将其传递给每个单元格的 collectionView。
在您的 collectionView cellForItemAtIndexPath 中,实现以下内容:
sharedManager.dictionaryProperty = [sharedManager.imageProperty objectAtIndex:indexPath.item];
//新建
NSArray *array = [sharedManager.dictionaryProperty objectForKey:sharedManager.emailStringProperty];
imageView.image = array[indexPath.item];
关于ios - 在 UITableviewcell 中使用 Collectionview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21961432/
我在 Storyboard 中有一个 collectionView,如下所示: 注意约束:Collection View.top = Search Bar.bottom 我不想要该行上方的 Colle
我有一个包含两个部分的 Collection View ,每个部分都有一个项目。部分中的单元格包含 Collection View ,我需要使高度单元格适合内容 Collection View 。 我
我见过将 Collection View 嵌套在 TableView 中的解决方案,但对于我的应用程序,我需要有 2 个 Collection View ,因为这样可以更轻松地执行其他操作。 因此,让
感谢帮助。 如上所示,CollectionView ItemSize.height 比 CollectionView.height 大。我只是在 viewDidLayoutSubviews() 中设置
我有一个collectionview(A),它可以作为“卡片 View ”来滑动。在最后一个卡/单元格中,我有另一个 Collection View (B)来显示更多单元格。到目前为止,一切都很好!一
我正在寻找一种方法,当您滚动到 collectionView 中的另一个单元格时,可以更改 imageView 中的图像。 因此,当滚动单元格的 (1) 时,我想更改图像 (2)。 创建此内容的最佳方
我的 NSCollectionView 项目集成了另一个 NSCollectionView。一切都很好,但在第一个 View 中选择项目时就不行了。 当我设置collectionView1.isSel
我是一名 Android 开发者,正在尝试学习 iO 开发。 我正在尝试在水平分页滚动器内实现垂直滚动 UI(就像 ViewPager 内的 RecyclerView)。 我知道我应该使用嵌套的 UI
我在collectionView中有一个collectionView,我希望能够选择第二个collectionView中的一个单元格来执行到另一个ViewController的segue。 目前,当我
我有这两个代表: #pragma mark = UICollectionViewDataSource - (NSInteger)collectionView:(UICollectionView*)co
嘿,我正在尝试在我的动态 Collection View 单元格之后添加一个静态 Collection View 单元格。例如在我的屏幕截图中,在“Study Grind Edition” Colle
是否可以通过在 Collection View Cell .swift 文件中编写代码来阻止我的 Collection View 滚动。我希望能够在用户点击单元格中的按钮时停止滚动,然后在再次按下按钮
我有一个用例,我想要呈现一组collectionViews(或复合 View )。使用 marionette.js 执行此操作的最佳方法是什么? 我的模型结构如下- A | |-- Collectio
我有一个 View Controller ,其中有 tableView 和 Collection View 。我为 collectionView 和 tableView 设置了相同的高度。 前半部分是
在 Visual Studio 2017 中,尝试存档 Xamarin Android 项目时,成功构建后出现以下错误: 无法创建应用程序存档“MyArchive”。这种类型的 CollectionV
我对 Collection View 完全陌生,请帮助我在 Collection View 中垂直和水平滚动单元格: viewcontroller.h #import @interface View
我在一个表格 View 单元格中有两个不同的 collectionView。原因是因为我试图找到实现一个水平 collectionView 和一个显示不同数据的垂直 collecitonView 的最
我想在另一个 collectionview 标题中实现一个 Collection View 幻灯片,但是当我尝试连接 uicollectionview 的导出时,我收到一条错误消息,指出导出无法连接到
您好,我已经为这个问题苦苦挣扎了一段时间,一直想不出来。 我想做的是,在 collectionview 单元格内按下一个按钮,然后执行到下一个单元格的转换。 这是我想在 collectionview
在 collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayo
我是一名优秀的程序员,十分优秀!