Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableView接收参数_Ios_Uitableview - Fatal编程技术网

Ios UITableView接收参数

Ios UITableView接收参数,ios,uitableview,Ios,Uitableview,UITableView(A),如果选择此tableview的一个单元格,它将推送到另一个视图(B)。如果按下视图(B)中的后退按钮,将运行此后退功能: - (void)pushBack { [self.navigationController popViewControllerAnimated:YES]; } 我想向视图(a)发送一个参数。该参数用于确定刷新视图(a)的需要。我该怎么办 提前谢谢你 要回答第一个问题,为了能够在从后台返回时显示启动图像,必

UITableView(A),如果选择此tableview的一个单元格,它将推送到另一个视图(B)。如果按下视图(B)中的后退按钮,将运行此后退功能:

    - (void)pushBack
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
我想向视图(a)发送一个参数。该参数用于确定刷新视图(a)的需要。我该怎么办


提前谢谢你

要回答第一个问题,为了能够在从后台返回时显示启动图像,必须将应用程序定义为无法在后台运行。这是通过将info.plist中的“应用程序不在后台运行”标志更改为“是”来实现的

  • 这是模拟器中的一个bug。如果你想在应用程序返回时显示Default.png,你有两个选择。第一种方法是在Info.plist中将
    UIApplicationExitsOnSuspend
    设置为
    YES
    。但是,这将要求您保存并加载应用程序状态,而不是让多任务为您完成工作。另一种方法是在
    -applicationWillResignActive:
    中使用Default.png覆盖应用程序,并在
    -applicationdibecomeactive:
    中删除它,就像启用密码锁时Dropbox所做的一样

  • 实现一个名为
    -(void)的方法将变得可见:(MyParameterType*)parameter
    (但您的参数可能不是指针)。然后,在
    -pushBack
    中,在弹出视图控制器之前,执行以下操作:


  • 您应该仔细阅读设计模式,它在iOS开发中对您非常有用

    通常,控制器不应直接告诉其他控制器的视图它需要刷新。
    ViewControllerA
    负责更新其视图。但是,控制器可以相互通信,以通知模型中的状态更改(或者这可以通过模型本身完成)

    在这种情况下,最简单的解决方案可能是让您的
    ViewControllerB
    ViewControllerA
    发送消息-因此您应该在
    ViewControllerA
    上定义一个接口,并在创建时将
    ViewControllerA
    的引用传递到
    ViewControllerB
    ,以便在你想要的。例如:

    ViewControllerA

    - (void)stateChanged
    {
        // Code to handle the change and update the view if it's visible.
        // Alternatively, just set a BOOL flag here and then check it in
        // viewWillAppear so that the view-update only happen later on when
        // the view is actually about to appear.
    }
    
    - (void)pushBack
    {
        [viewControllerA stateChanged];
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    ViewControllerB
    中的
    pushBack
    方法中

    - (void)stateChanged
    {
        // Code to handle the change and update the view if it's visible.
        // Alternatively, just set a BOOL flag here and then check it in
        // viewWillAppear so that the view-update only happen later on when
        // the view is actually about to appear.
    }
    
    - (void)pushBack
    {
        [viewControllerA stateChanged];
        [self.navigationController popViewControllerAnimated:YES];
    }
    

    您可以将任何需要的额外值传递到
    stateChanged
    ——这只是一个示例。一种更简洁的方法是使用代理或从控制器上观察模型本身,但我认为这更容易理解,因为您正在学习MVC以及如何最好地隔离和分离M、V和C。

    如果您想问两个问题,请分别问两个问题!