如何将数据从一个视图传递到下一个视图?(How to pass data from one view to the next?)

编程入门 行业动态 更新时间:2024-10-28 12:29:27
如何将数据从一个视图传递到下一个视图?(How to pass data from one view to the next?)

我正在制作下载排队系统来下载视频。 处理下载的排队代码在另一个viewconntroller中。 现在我的问题是如何将下载的URL传递给另一个视图,而无需像这样推送到另一个视图控制器:

ViewConntroller *View = [[ViewConntroller alloc] init]; view.url = "" [self presentModalViewController:View animated:NO];

我也知道代表们有一种方法,但是你也不必为了被召唤的观点而受到重视吗?

编辑我有一个NSURL ,我想发送到另一个viewconntroller。 我知道有协议的方法或上面的方法。 但是我不想提供viewconntroller来发送信息。 我只想在按下按钮后立即发送它而不进入视图本身

I am making a download queueing system to download videos. The queueing code to handle the downloads is in another viewconntroller. Now my question is how can i pass the URL of the download to the other view without pushing to another view controller like this:

ViewConntroller *View = [[ViewConntroller alloc] init]; view.url = "" [self presentModalViewController:View animated:NO];

I also know there is a way through delegates but don't you also have to weight for the view to be called upon aswell?

EDIT I have an NSURL in which i want to send to another viewconntroller. I know there is the method of Protocols or the method above. However i do not want to present a viewconntroller to send the info. I just want to send it as soon as the button is pressed without going to the view itself

最满意答案

我不想提供viewconntroller来发送信息。 我只想在按下按钮后立即发送它而不进入视图本身

通常,您不能这样做:您可以将数据发送回视图控制器链,但只有在您呈现发送数据的视图控制器时才可以向前发送数据。

您需要采用不同的方法来解决您的问题:不是将信息发送到另一个视图控制器,而是将该数据发送到公共场所,一旦呈现它就可以被另一个视图控制器找到。 这个“共同的地方”通常被称为模型 (在模型 - 视图 - 控制器意义上)。 使用URL队列创建单个对象,并从第一个视图控制器调用其addUrl:方法。 然后,第二个视图控制器可以调用getUrlQueue方法来检查所有排队的URL。

插图

I figured it out and in then end i sent a url through the calling of a -(void) statement form another view.

For example:

In the secondviewconntroller.h file i would set a void statement...

-(void)addDownloadRequest:(NSString *)request;

This line of code means it can be called upon in other class and viewconntrollers.

Then in my secondviewconntroller.m file i would set the -(void) with the function i want to preform when it has been called so in my case i wanted to use the url to download so...

-(void)addDownloadRequest:(NSString *)request{ NSLog(@"Called"); NSString *URL = request; ///Download code here now i have the URL }

The code above gets the sent URL in the form as a string called request and then sets the URL variable to the sent string called request.

In my first viewconntroller I then need to call the -(void) statement so I...

secondviewconntroller *theVIEW=[[secondviewconntroller alloc]init]; [theVIEW addDownloadRequest:@"The URL or STRING wanting to be sent"];

This code I place in an -(IBAction) which allowed me to send the variable or string when i called upon the action. This successfully allowed the download URL to be sent through class.

Thanks for all of your help.

更多推荐

本文发布于:2023-08-06 23:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1457448.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   如何将   数据   view   pass

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!