【问题标题】:How to add a selected UITableViewController value to a previous UITableViewController?如何将选定的 UITableViewController 值添加到以前的 UITableViewController?
【发布时间】:2011-05-29 01:42:29
【问题描述】:

用户单击“远程”按钮,然后加载以下 UITableViewController:

然后用户选择我调用的任何值:

[self.navigationController popViewControllerAnimated:YES];

再次回到之前的 UITableViewController(屏幕截图 1)。

如何将选定的值添加到 UITableViewController?

我希望我说得通。

【问题讨论】:

    标签: iphone ios uinavigationcontroller uitableview


    【解决方案1】:

    在您的remote recipients table view controller 中,您拥有用于加载表格的数组(例如myTestArray)。将其作为财产保存。并且还有一个 NSInteger 属性(比如selectedRow),它将识别用户选择了哪一行。而当你回到add recipient table view controller时,就可以知道是哪一行被选中了

    [remoteRecipientsController.myTestArray objectAtIndex:remoteRecipientsController.selectedRow];
    

    或者使用委托。选择行后,远程接收者将回叫,告知选择了哪一行。

    更新: 如果您无权访问视图控制器,请使用委托。

    你可以在委托方法中同时获取数组和选中的行,如下:

    -(void) remoteRecipient:(RemoteRecipientController *) remoteRecipientController didSelectRow:(NSInteger) row {
    // Get the selected row
    ... = [remoteRecipientController.myTestArray objectAtIndex:row ];
    }
    

    或者您也可以将委托配置为仅返回选定的行(作为您的字符串),如下所示:

    -(void) remoteRecipient:(RemoteRecipientController *) remoteRecipientController didSelectRow:(NSString *) selectedRecipient {
    
    }
    

    当然,在这种情况下,您需要让远程接收控制器将所选行作为 NSString 传递给委托。

    【讨论】:

    • 是的,但我无法在“添加收件人”控制器中访问远程视图控制器。
    • 如果您无权访问视图控制器,请使用委托(我假设您正在使用 xib 创建视图)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 2010-12-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多