需要帮助将 NSURL 字符串添加到数组中

发布于 2024-12-22 13:25:46 字数 879 浏览 2 评论 0原文

我有一个数据数组,显示带有标签信息的项目列表。在媒体部分,我想插入一个 URL 来运行视频。在 @"Play Video" 字符串之后加载 url(使用 NSURL)的正确过程是什么?然后,当按下按钮时,URL 将加载并显示视频。每个条件的 URL 都不同。感谢您的帮助!

- (void)createData {

NSMutableArray *playList = [[NSMutableArray alloc] init];
Play *play;
NSArray *media;

play = [[Play alloc] init];
play.title = @"Introduction";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

play = [[Play alloc] init];
play.title = @"Rule #1";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

play = [[Play alloc] init];
play.title = @"Rule #2";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

I have a data array showing a list of items with label information. On the media section, I want to insert a URL to run a video. What would be a correct procedure to load a url (using NSURL) after the @"Play Video" string? Then when the button is pressed, the url would load and display the video. THe URL is different for each condition. Thanks for any assistance!!

- (void)createData {

NSMutableArray *playList = [[NSMutableArray alloc] init];
Play *play;
NSArray *media;

play = [[Play alloc] init];
play.title = @"Introduction";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

play = [[Play alloc] init];
play.title = @"Rule #1";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

play = [[Play alloc] init];
play.title = @"Rule #2";
play.part = @"Getting in the Game";
media = [[NSArray alloc] initWithObjects:@"Play Video", nil];
play.media = media;
[playList addObject:play];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热风软妹 2024-12-29 13:25:46
Play *play;
NSArray *media;
NSURL *url;

play = [[Play alloc] init];
play.title = @"Introduction";
play.part = @"Getting in the Game";
//add this line
url = [NSURL urlWithString:@"http://abc.com/video.mp4"];
media = [[NSArray alloc] initWithObjects:@"Play Video",url, nil];
play.media = media;
[playList addObject:play];
Play *play;
NSArray *media;
NSURL *url;

play = [[Play alloc] init];
play.title = @"Introduction";
play.part = @"Getting in the Game";
//add this line
url = [NSURL urlWithString:@"http://abc.com/video.mp4"];
media = [[NSArray alloc] initWithObjects:@"Play Video",url, nil];
play.media = media;
[playList addObject:play];
爱本泡沫多脆弱 2024-12-29 13:25:46

您的意思是如何将 NSURL 作为第二项包含在 NSArray media 中?

media = [[NSArray alloc] initWithObjects:@"Play Video", myNsUrl, nil];

有关如何创建来自 URL 字符串的 NSURL 对象。

如果您已经有一个 NSURL 对象,并且只想添加该对象的字符串表示形式而不是 NSURL 对象本身:

media = [[NSArray alloc] initWithObjects:@"Play Video", [myNsUrl absoluteString], nil];

一旦您有了 media 数组,就可以将“Play Video”字符串检索为 < code>[media objectAtIndex:0] 并且可以通过 [media objectAtIndex:1] 检索 URL。

从面向对象的角度来看,也许理想情况下,您不会在此处使用数组,而是更愿意为您的程序创建一个 Media 类来实例化。但上面回答了问题(如何将 NSURL 添加到数组)。

You mean how to include the NSURL as a second item in your NSArray media?

media = [[NSArray alloc] initWithObjects:@"Play Video", myNsUrl, nil];

See https://stackoverflow.com/a/1981508/436641 for some caveats and sample code on how one might create an NSURL object from a URL string.

If you already have an NSURL object and want to just add the string representation of that object rather than the NSURL object itself:

media = [[NSArray alloc] initWithObjects:@"Play Video", [myNsUrl absoluteString], nil];

Once you have your media array, the "Play Video" string can be retrieved as [media objectAtIndex:0] and the URL can be retrieved as [media objectAtIndex:1].

From an OO perspective, perhaps ideally, you wouldn't use an array here but would rather create a Media class for your program to instantiate. But the above answers the question (how to add an NSURL to an array).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文