2016-09-15 84 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