如何更新 NSString
我用下面的代码打印 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 NSMutableString。这就是为什么你不能改变 NSString 的值。
You should use NSMutableString. That's why you cant change the value of your NSString.