需要帮助将 NSURL 字符串添加到数组中
我有一个数据数组,显示带有标签信息的项目列表。在媒体部分,我想插入一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的意思是如何将 NSURL 作为第二项包含在 NSArray
media
中?有关如何创建来自 URL 字符串的 NSURL 对象。
如果您已经有一个 NSURL 对象,并且只想添加该对象的字符串表示形式而不是 NSURL 对象本身:
一旦您有了
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
?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:
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).