我正在使用收藏视图,因为如果我点击任何一个图像,它将移动到下一个屏幕,用户可以在textview中输入图片的详细信息,如果用户按下保存按钮第二个视图控制器它应该保存文本并移动到第一个视图控制器,并应该把一个标记符号,以显示此图像有笔记。像这样收藏查看
为此我所做的是, 我创建了一个字典,存储所触摸的图像作为键和值作为输入的字符串在第二个视图控制器.i不要在此之后,我想标记一个符号,如果用户转到上一个屏幕。 请帮我做这件事
//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];
}
请说一些想法做到这一点。
您只需要在该indexpath修改数据源,以便重新加载表格时,可以看到单元格中的复选标记 –
谢谢@Teja Nandamuri,但是我没有将字典发送给第一个视图控制器。以及我必须重新加载收藏视图单元格的位置。如果用户触摸他们提供的相同图片,则输入的文本应该在第二个视图控制器中。请说这个 – user6183984
你的代码的奇怪格式不鼓励阅读它。 – vikingosegundo