AssetScreenPopupViewController

AssetScreenPopupViewController

This question already has answers here:
Passing Data between View Controllers

(46个答案)


6年前关闭。




我有Button Click事件,它显示一个AssetScreenPopupViewController,在AssetScreenPopupViewController中,我正在向NSNumber动态添加一个NSMutableArray(emailClkArray)

当我关闭视图控制器时,我正在我的BrowseProgrammingTools中检索此emailClkArray。但是我总是得到空白数组

我的呈现modalviewcontroller的代码是
- (void)imageViewTapped:(UITapGestureRecognizer *)gr {
    AssetScreenPopupViewController * assetController =
    [[AssetScreenPopupViewController alloc]init];
    assetController.AssetContentArray = tableData_one;
    assetController.myStringValue = gridPopUpController.assetName.text;
    [self.navigationController presentViewController:assetController animated:NO
       completion:nil];
    NSLog(@"Asset ARRAY %@",assetController.emailClkArray);
    [self.navigationController.delegate self];
}

我在其中向数组添加值的ModalViewController类方法如下
 - (IBAction)emailClkBtn:(id)sender {
          [self.emailClkArray replaceObjectAtIndex:k withObject:[NSNumber numberWithInt:1]];
          [self.emailBtnOutlet setBackgroundImage:newImage1 forState:UIControlStateNormal];
          NSLog(@"WMA  dhbc%@",self.emailClkArray);
       }

当我关闭视图控制器时,我已经将emailClkArray分配给
像这样的ParentViewController MutableArray
- (IBAction)dismissClk:(id)sender {
     BrowseProgrammingTools *browsePrgTools = [[BrowseProgrammingTools alloc]init];
     browsePrgTools.emailClkArray = self.emailClkArray;
     [self dismissViewControllerAnimated:NO completion:Nil];
}

当我像这样在viewDidAppearBrowseProgrammingTools方法中打印此数组时
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:YES];
    self.emailClkArray = [[NSMutableArray alloc]init];
    NSLog(@"DNW%@",self.emailClkArray);
}

我正在这样的空白数组
DNW(
 )

请帮助我如何获得价值?

最佳答案

您误解了控制流程。

当您调用presentViewController:animated:completion:时,该调用将立即返回。之后的下一行将在视图控制器甚至显示到屏幕之前执行。

您应该将AssetScreenPopupViewController设置为具有委托属性。定义一个协议,当用户完成选择后,AssetScreenPopupViewController将使用该协议与调用它的视图控制器进行通信。

10-06 05:51