我正在使用收藏視圖,因爲如果我點擊任何一個圖像,它將移動到下一個屏幕,用戶可以在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