从popover返回后,如何在collectionview单元格中填充文本字段



有人能帮我吗…我有一个集合视图,显示从SQLite数据库检索到的数据。集合视图单元格中的某些文本字段需要使用弹出窗口中的预定义列表进行更新。

弹出窗口显示正确的值,我确实检索了所选的值,但我无法用该值更新collectionview中的文本字段。我假设我需要在启动segue时使用indexpath指定包含文本字段的单元格,但我不知道如何指定。

我用这个启动popover:

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    if (textField.tag == 101) {
        Global.Table = @"Access";
        Global.Code = @"G";
        Global.Request = @"Access";
        [self performSegueWithIdentifier:@"PopUp" sender:self];
        return NO;
    }
    else {
        return YES;
    }
}

popover在表视图中选择正确的值后发送通知,并被驳回。

- (void)receivedNotification:(NSNotification *) notification {
    if ([[notification name] isEqualToString:@"scroller"]) {
        if ([Global.Request isEqualToString:@"Access"]) {
          NSLog(@"Returnvalue is %@",Global.Value);
          //this is where the problem arises, I cannot access the text field to update the value, the return value is correct.
          [self.collectionviewManagement selectItemAtIndexPath:0 animated:NO scrollPosition:0];
          WDSCellManagement *cell = [_collectionviewManagement dequeueReusableCellWithReuseIdentifier:@"CellManagement" forIndexPath:0];
          cell.AccessPersons.text = Global.Value;
        }
    }
}

非常感谢你的帮助!

您使用委托模式,就像任何视图-控制器交互一样:

YourPopupController.h:

#import <UIKit/UIKit.h>
@class YourPopViewController;
@protocol YourPopupViewControllerDelegate <NSObject>
@optional
- (void)yourPopupViewController:(YourPopViewController *)yourPopupViewController
                  returnedValue:(NSString *)value;
@end
@interface YourPopupViewController : UITableViewController
@property (weak, nonatomic) id<YourPopupViewControllerDelegate> delegate;
@end

YourPopupViewController.m:

- (void)receivedNotification:(NSNotification *) notification {
    if ([[notification name] isEqualToString:@"scroller"]) {
        if ([Global.Request isEqualToString:@"Access"]) {
          if ([_delegate respondsToSelector:@selector(yourPopupViewController:returnedValue:)]) {
              [_delegate yourPopupViewController:self
                                   returnedValue:Global.Value];
          }
        }
    }
}

然后,您在呈现视图控制器中遵守YourPopupViewControllerDelegate协议,并在调用委托方法时更新集合视图,从而取消弹出视图控制器。

最新更新