如何更新 NSString

发布于 2024-11-19 04:50:47 字数 1678 浏览 1 评论 0原文

我用下面的代码打印 YouTube 视频并水平显示它们,滑动查看下一个视频。我希望每个视频都能够共享链接,我为此添加了 AddThis。

但是,我不知道如何动态更新视频链接(或为每个视频显示一个新按钮)。

UIWebView *aVideo;    
int size = 0;
for (int i=0; i<[vidsID count]; i++) {
    NSString* embedHTML = @" \
    <html><head> \
    <style type=\"text/css\"> \
    body { \
      background-color: transparent; \
      color: white; \
    } \
    </style> \
    </head><body style=\"margin:0\"> \
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed> \
    </body></html>";  

    NSString *videoLink = [@"http://youtube.com/watch?v=" stringByAppendingString:[vidsID objectAtIndex:i]];
    NSString *html = [NSString stringWithFormat:embedHTML, [@"http://youtube.com/watch?v=" stringByAppendingString:[vidsID objectAtIndex:i]], 320.f, 242.f];  

    addThisButton = [AddThisSDK showAddThisButtonInView:self.view
                                              withFrame:CGRectMake(10, 5, 70, 25)
                                                 forURL:videoLink
                                              withTitle:@"Watch this video!"
                                            description:@"Watch this video: "];

    addThisButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; 

    aVideo = [[UIWebView alloc] init];
    aVideo.frame = CGRectMake(320*i, 45, 320, 242);
    [aVideo loadHTMLString:html baseURL:nil];
    [aVideo setBackgroundColor:[UIColor clearColor]];

    [myScrollView addSubview:aVideo];

    size = size+320;
    [aVideo release];
}

I print YouTube videos in the following code and display them horizontally, swipe for next video. I'd like each video to be able to share the link, i added AddThis for this purpose.

However, I don't know how to update the video link dynamically (or display a new button for each video).

UIWebView *aVideo;    
int size = 0;
for (int i=0; i<[vidsID count]; i++) {
    NSString* embedHTML = @" \
    <html><head> \
    <style type=\"text/css\"> \
    body { \
      background-color: transparent; \
      color: white; \
    } \
    </style> \
    </head><body style=\"margin:0\"> \
    <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    width=\"%0.0f\" height=\"%0.0f\"></embed> \
    </body></html>";  

    NSString *videoLink = [@"http://youtube.com/watch?v=" stringByAppendingString:[vidsID objectAtIndex:i]];
    NSString *html = [NSString stringWithFormat:embedHTML, [@"http://youtube.com/watch?v=" stringByAppendingString:[vidsID objectAtIndex:i]], 320.f, 242.f];  

    addThisButton = [AddThisSDK showAddThisButtonInView:self.view
                                              withFrame:CGRectMake(10, 5, 70, 25)
                                                 forURL:videoLink
                                              withTitle:@"Watch this video!"
                                            description:@"Watch this video: "];

    addThisButton.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; 

    aVideo = [[UIWebView alloc] init];
    aVideo.frame = CGRectMake(320*i, 45, 320, 242);
    [aVideo loadHTMLString:html baseURL:nil];
    [aVideo setBackgroundColor:[UIColor clearColor]];

    [myScrollView addSubview:aVideo];

    size = size+320;
    [aVideo release];
}

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

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

发布评论

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

评论(1

与风相奔跑 2024-11-26 04:50:47

您应该使用 NSMutableString。这就是为什么你不能改变 NSString 的值。

You should use NSMutableString. That's why you cant change the value of your NSString.

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