2016-09-15 72 views
-1

我正在使用收藏视图,因为如果我点击任何一个图像,它将移动到下一个屏幕,用户可以在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]; 



} 

请说一些想法做到这一点。

+0

您只需要在该indexpath修改数据源,以便重新加载表格时,可以看到单元格中的复选标记 –

+0

谢谢@Teja Nandamuri,但是我没有将字典发送给第一个视图控制器。以及我必须重新加载收藏视图单元格的位置。如果用户触摸他们提供的相同图片,则输入的文本应该在第二个视图控制器中。请说这个 – user6183984

+0

你的代码的奇怪格式不鼓励阅读它。 – vikingosegundo

回答

0

你应该在你的集合视图控制器中创建一个字典,并且这个dic应该保存单元格是否应该检查过的信息。您可以使用按键作为indexpath,

例如:

在您的收藏视图控制器:

dictionary = @{ @"1" : @[ your-data, NO], 
       @"2" : @[ your-data, NO], 
       @"3" : @[ your-data, NO]}; 

    here keys @"1",@"2",@"3" serve as indexpath 

,当你点击的图像,在didSelectRow委托方法,通过这本词典以及indexPath到secondView控制器并在第二个视图控制器中对其进行修改。

而且一旦你来自第二视图控制器背面,通过这个字典到您的收藏视图控制器

 dictionary = @{ @"1" : @[ your-data, NO], 
       @"2" : @[ your-data, YES], 
       @"3" : @[ your-data, NO]}; 

并重新加载您的收藏视图。

+0

@感谢Teja Nandamuri,我应该发送一个代码,请看我的代码? – user6183984

+0

你可以尝试我建议的方式,如果你仍然不能,请用你试过的方式更新你的问题,我们可以从那里帮助你。 –

+0

实际上,我试图从第二个视图控制器发送字典到使用委托的第一个视图控制器。但我通过断点控制不正确。 – user6183984