这是我的AddUsersViewController,其中声明了'recipients'属性:
AddUsersController:
@interface AddUsersViewController : UITableViewController
@property (nonatomic, retain) NSMutableArray *recipients;
'AddUsersViewController'和'ComposeViewController'之间有一个推送segue。我想从'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关联起来。请帮忙?我在正确的道路上吗?
答案 0 :(得分:2)
首先将recipients
数组添加到ComposeViewController
公共接口:
@interface ComposeViewController : UIViewController
@property (nonatomic, strong) NSMutableArray *recipients;
// ...
@end
然后在-(void)prepareForSegue:sender:
控制器中实施AddUsersController
方法。它将在执行segue之前调用。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ComposeViewController *composeViewController = segue.destinationViewController;
composeViewController.recipients = self.recipients;
}