Objective c 集合视图
我正在使用集合视图,如果我点击任何一个图像,它将移动到下一个屏幕,用户可以在textview中输入图片的详细信息,如果用户在第二个视图控制器中按下save按钮,它将保存文本并移动到第一个视图控制器,并应放置一个标记符号,用于显示此图像的注释。类似这样 我所做的就是, 我创建了一个字典,在第二个视图控制器中将触摸的图像存储为键,将值存储为输入的字符串。 请帮我做这个Objective c 集合视图,objective-c,uicollectionview,Objective C,Uicollectionview,我正在使用集合视图,如果我点击任何一个图像,它将移动到下一个屏幕,用户可以在textview中输入图片的详细信息,如果用户在第二个视图控制器中按下save按钮,它将保存文本并移动到第一个视图控制器,并应放置一个标记符号,用于显示此图像的注释。类似这样 我所做的就是, 我创建了一个字典,在第二个视图控制器中将触摸的图像存储为键,将值存储为输入的字符串。 请帮我做这个 //collection view methods -(NSInteger)numberOfSectionsInCollect
//collection view methods
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.imageArray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
PicturesCollectionViewCell *Cell1 = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell1" forIndexPath:indexPath];
NSLog(@"%@",self.imageArray);
Cell1.self.imageView.image=[self.imageArray objectAtIndex:indexPath.row];
Cell1.layer.borderWidth = 2.0f;
Cell1.layer.borderColor = [UIColor blackColor].CGColor;
//button to tap
UIButton *tapButton = [[UIButton alloc]init];
tapButton.frame = CGRectMake(0, 0, 96, 82);
[tapButton addTarget:self action:@selector(Tap:) forControlEvents:UIControlEventTouchUpInside];
[tapButton setTag:indexPath.row];
[Cell1.contentView addSubview:tapButton];
self.imageSelected = [self.imageArray objectAtIndex:indexPath.row];
NSLog(@" the image is:%@",self.imageSelected);
return Cell1;
}
-(IBAction)Tap:(id)sender
{
UIButton *btn = (UIButton *)sender;
self.key = @(btn.tag);
int tag = [self.key intValue];
self.imageSelected = [self.imageArray objectAtIndex:tag];
NSLog(@" image selected in picture confirm screen %@",self.imageSelected);
NotesViewController *NotesVC = [self.storyboard instantiateViewControllerWithIdentifier:@"NotesVC"];
NotesVC.self.notes_Array = self.imageSelected;
[self.navigationController pushViewController:NotesVC animated:YES];
}
2nd view controller -Notes View Controller
- (IBAction)bnt_Save_Notes:(id)sender {
if (self.txtview_Notes.text.length == 0) {
[StaticHelper showAlertWithTitle:nil message:@"Notes Should Not be empty" onViewController:self];
}
else
{
self.string = self.txtview_Notes.text;
NSLog(@" the noted string is :%@",self.string);
PicViewController *PictureVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PictureVC"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
[dict setObject:self.string forKey:self.notes_Array];
[self.navigationController popViewControllerAnimated:YES];
}
请说出一些想法。您应该在集合视图控制器中创建一个字典,该dic应该包含单元格应该检查或不应该检查的信息。您可以使用这些键作为索引 例如: 在集合视图控制器中:
dictionary = @{ @"1" : @[ your-data, NO],
@"2" : @[ your-data, NO],
@"3" : @[ your-data, NO]};
here keys @"1",@"2",@"3" serve as indexpath
当您单击图像时,在didSelectRow委托方法中,将此字典和indexPath一起传递给secondView控制器,并在secondView控制器中修改它
从第二个视图控制器返回后,将此字典传递给集合视图控制器
dictionary = @{ @"1" : @[ your-data, NO],
@"2" : @[ your-data, YES],
@"3" : @[ your-data, NO]};
然后重新加载集合视图。您只需在该索引XPath处修改数据源,以便在重新加载表时,可以在单元格中看到复选标记,谢谢@Teja Nandamuri,但我没有将字典发送给first view controller。我必须在此处重新加载集合视图单元格。如果用户触摸到他们提供详细信息的同一张图片,输入的文本应该在second view controller中。请这样说您的代码奇怪的格式不鼓励阅读。@谢谢Teja Nandamuri,我可以发送代码吗,请查看我的代码?您可以尝试我建议的方式,如果您仍然不能,用您尝试过的内容更新您的问题,我们可以从那里提供帮助。实际上,我尝试使用委托将字典从第二视图控制器发送到第一视图控制器。但我遇到了一个断点,控件运行不正常。我在第一视图控制器中获得了字典,现在,如果我再次触摸相同的图像,我想在notes视图控制器中显示输入的文本…为此,我想做什么。请帮助我