ios - 试图将数据从一个类发送到另一个类 ios(解析)

标签 ios parse-platform

抱歉,如果这真的很简单或已经解释过了,但我一直在寻找,虽然我一直在尝试不同的东西,但我没有读到任何东西给我任何错误(所以我将能够运行该应用程序)。我一直在尝试将变量“收件人”从一个类 AddUsersTableViewController 传输到另一个类 ComposeViewController。到目前为止我还没有成功。我正在使用 Parse 并将其基于 PFObject。

这是我的 AddUsersViewController,其中声明了“收件人”属性:

AddUsersController:

@interface AddUsersViewController : UITableViewController

@property (nonatomic, retain) NSMutableArray *recipients;

“AddUsersViewController”和“ComposeViewController”之间存在推送转场。我想从“ComposeViewController”中的 AddUsers 访问变量声明“recipients”,我想在方法中使用它(上传消息)。这是我的代码:

    ComposeViewController:

            -(void)newMessage {
            PFObject *text = [PFObject objectWithClassName:@"message"];
            [text setObject:addValues forKey:@"file"];
            [text setObject:self.recipients forKey:@"recipientIds"];
            [text setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
            [text setObject:[[PFUser currentUser] username] forKey:@"senderName"];
            [text saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)

       }

我试图做的是让用户按下附加到 ComposeViewController 并在其上声明的“adduser”按钮,通过 segue 调出 AddUserViewController(一个 tableviewcontroller),选择收件人,关闭“AddUsersViewController”并让我的 'ComposeViewController' 发送带有收件人(和 recipientIds)的文件。现在我知道我在某些方面搞砸了,但我不知道如何将 AddUsers 中的收件人关联到 ComposeViewController。请帮助?我在正确的道路上吗?

最佳答案

首先将 recipients 数组添加到您的 ComposeViewController 公共(public)接口(interface):

@interface ComposeViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *recipients;
// ...

@end

然后在您的 AddUsersController Controller 中实现 -(void)prepareForSegue:sender: 方法。它将在执行 segue 之前被调用。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ComposeViewController *composeViewController = segue.destinationViewController;
    composeViewController.recipients = self.recipients;
}

关于ios - 试图将数据从一个类发送到另一个类 ios(解析),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26491699/

相关文章:

ios - 在两个静态 UITableViewCell 之间插入带有 UIPickerView 的行时出现 NSRangeException

ios - 如何根据通过 TableView 进行的选择在 uiview 中显示不同的 View Controller (请参阅说明中的图片)?

ios - 使用未解析的标识符 PFFacebookUtils

android - 在解析中,发送的推送始终为 0

swift - 解析为 Kinvey 查询

php - 这是哪种图像格式?

ios - swift : Width of CALayer after animation

ios - 我无法解析IOS驱动程序页面源

ios - 使用 Parse.com 未显示 Pins

node.js - 如何使用图像 URL 将图像上传到 AWS S3?