【问题标题】:data not getting passed with prepareForSegue or pushViewController数据未通过 prepareForSegue 或 pushViewController 传递
【发布时间】:2014-07-01 20:45:23
【问题描述】:

我已经尝试了在视图控制器之间传递这些数据的所有方法,这两种方法都以模态方式表示为页面表。

在 ViewController 1 .h 中 —————————

@property (strong, nonatomic) NSMutableDictionary * updatableProduct ;
//@property (strong, nonatomic) NSDictionary * updatableProduct ; //tried

在 ViewController 1.m 中 —————————

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath{

static NSString * cellIdentifier = @"Cell";
TailorOUCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

cell.updateOrder.tag = indexPath.row;
[cell.updateOrder addTarget:self action:@selector(nowUpdateOrder:) forControlEvents:UIControlEventTouchUpInside];

orderToUpdate = [orderQueryResults objectAtIndex:indexPath.row];

return cell;
}


-(void)nowUpdateOrder:(id)sender{

UIButton *senderButton = (UIButton *)sender;
updatableProduct = [orderQueryResults objectAtIndex:(long)senderButton.tag];

[self performSegueWithIdentifier:@"updateOrder" sender:updatableProduct];
//[self performSegueWithIdentifier:@"updateOrder" sender:self]; //tried

}


-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

if ([segue.identifier isEqualToString:@"updateOrder"]) {
    OUEditView * ouv = (OUEditView *)segue.destinationViewController;
    ouv.orderDetails = updatableProduct;
    [segue.destinationViewController setModalPresentationStyle:UIModalPresentationPageSheet];

}

}

在 ViewController 2.h 中 —————————

@property (strong, nonatomic) NSMutableDictionary * orderDetails ;

在 ViewController 2.m 中 —————————

@synthesize orderDetails;

但是日志中的 orderDetails = null

任何帮助!

【问题讨论】:

    标签: ios objective-c pass-data


    【解决方案1】:

    您需要在代码中添加断点或日志语句并查看发生了什么。

    • 是否调用了 prepareForSegue?
    • IF 语句是否与标识符匹配?
    • “updatableProduct”中的值不是 nil 吗?
    • 您是在查看 viewDidLoad 中的 ouv.orderDetails 的值还是 viewWillAppear,而不是在 init 方法中? (初始化方法触发 在调用 prepareForSegue 之前。)

    【讨论】:

    • 我应该在哪里调用 ouv.orderDetails ?、viewDidAppear 或 viewWillAppear
    • viewWillAppear 和 viewDidLoad 甚至在 prepareForSegue 之前就被启动了,奇怪的是操作顺序.. prepareForSegue > nowUpdateOrder > prepareForSegue >。然后是其他窗口的viewDidAppear .. 并且仍然在这里viewDidAppear中的值为null。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多