【问题标题】:How to fill a text field in a collectionview cell after returning from popover从popover返回后如何在collectionview单元格中填充文本字段
【发布时间】:2014-04-28 10:15:12
【问题描述】:

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

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

我使用这个来启动弹出窗口:

-(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;
    }
}

在表格视图中选择正确的值后弹出框会发送通知并被关闭。

- (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;
        }
    }
}

非常感谢您的帮助!

【问题讨论】:

    标签: ios7 uicollectionview uicollectionviewcell


    【解决方案1】:

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

    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];
              }
            }
        }
    }
    

    然后,您在 presenting 视图控制器中遵循 YourPopupViewControllerDelegate 协议,并在调用委托方法时更新集合视图,从而关闭弹出视图控制器。

    【讨论】:

      猜你喜欢
      • 2018-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2021-11-01
      相关资源
      最近更新 更多