使用[popviewcontroller]传回数据,然后重新加载数据 [英] Pass back data using [popviewcontroller], and reload data

查看:129
本文介绍了使用[popviewcontroller]传回数据,然后重新加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://imgur.com/2lAJmVd

在上面提供的图片中,显示了三个视图控制器.

In the picture provided above, shows three view controllers.

让我们按照显示顺序依次调用视图控制器 A B C .



Let's call the view controllers A, B, and C in the order they're displayed.



View Controller A 通过单击表格单元格来传递已解析的jSON数据.这将填满总销售,折扣等".使用 prepareForSegue 方法在 View Controller B 中的字符串/标签.

View Controller A passes parsed jSON data by clicking on the table cell. This fills up the "total sales, discounts, etc." strings/labels inside of the View Controller B using a prepareForSegue method.

此数据基于开始时间/结束时间,并且执行segue时的默认参数会提供当日上午8点到晚上10点之间的信息.

解析字符串看起来像这样

This data is based on a start time/end time and the default parameter when performing the segue gives information from 8 AM to 10 PM of the current day.

The parsing string looks like this

NSDate *currentDate = [NSDate date];
            NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
            [dateformatter setDateFormat:@"YYYY-MM-dd"];
            NSString *theDate = [dateformatter stringFromDate: currentDate];

NSString *salesStr = @"http://";
salesStr = [salesStr stringByAppendingString:host];
salesStr = [salesStr stringByAppendingString:@":8080/sales.php?password="];
salesStr = [salesStr stringByAppendingString:pass];
salesStr = [salesStr stringByAppendingString:@"&db="];
salesStr = [salesStr stringByAppendingString:db];
salesStr = [salesStr stringByAppendingString:@"&sdate="];
salesStr = [salesStr stringByAppendingString:theDate];
salesStr = [salesStr stringByAppendingString:@"%2008:00:00&edate="];
salesStr = [salesStr stringByAppendingString:theDate];
salesStr = [salesStr stringByAppendingString:@"%2022:00:00"];

View Controller B 中,您会看到一个标记为"开始时间"的按钮.此按钮将启动推送服务 View Controller C .在这个新的视图控制器中,您可以选择日期和时间,日期和时间将显示在日期选择器上方的UILabel中.日期选择器下方的按钮是IBAction,并使用

Inside of the View Controller B, you can notice a button labeled "Start Time". This button initiates a push segue to View Controller C. In this new view controller, you are able to select a date and time and it is displayed in the UILabel above the date picker. The button below the date picker is an IBAction and uses

[self.navigationController popViewControllerAnimated:YES];





我的问题是: 如何在 View Controller C 中选择日期/时间,按下按钮,然后发送该日期/时间位于UILabel中的信息添加到 View Controller B ,以便可以用来更新已解析的信息?

My question is: How am I able to select a date/time in View Controller C, press a button, and send that information located in the UILabel to View Controller B so it can be used to update the parsed information?

我想到的一种方法是让按钮设置为 View Controller B ,然后根据日期/时间选择重新解析信息,但这只会导致过多的结果导航控制器堆叠"对我来说似乎效率不高.

One way I could think of doing this is to have the button segue to View Controller B, and RE-PARSE the information based on the date/time selection, but that would just cause too much 'navigation controller stacking' and just doesn't seem efficient to me.

任何建议都值得赞赏.

推荐答案

Hacker的方法可行.

Hacker's approach would work.

Apple的文档提出了一种稍有不同的技术.使用一种视图控制器C可以用来与视图控制器B进行通信的方法来定义一个简单的协议.

Apple's documentation suggests a slightly different technique. Define a simple protocol with a method that view controller C can use to communicate with view controller B.

然后为视图控制器C提供符合该协议的委托属性.

Then give view controller C a delegate property that conforms to that protocol.

在您的prepareForSegue方法中,将自己设置为视图控制器C的委托.

In your prepareForSegue method, set yourself as view controller C's delegate.

然后,在视图控制器C中,当用户更改日期并单击按钮时,调用委托方法以通知视图控制器B用户在您弹出自己之前更改了日期值.

Then, in view controller C, when the user changes the date and clicks the button, invoke a delegate method to notify view controller B that the user changed the date value before popping yourself.

我建议也添加一个取消按钮,以便用户可以放弃所做的更改.在这种情况下,您只需要在弹出之前跳过调用委托方法即可.

I would suggest adding a cancel button as well, so the user can discard their changes. In that case, you just would skip calling the delegate method before popping.

这篇关于使用[popviewcontroller]传回数据,然后重新加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆