【发布时间】:2011-12-13 21:41:43
【问题描述】:
很抱歉这个问题太长了,但我已经坚持了好几天了,并且已经用尽了所有其他帮助。
目前,我有一个带有四个标签的标签栏应用程序。在第二个选项卡(SecondViewController)中,我在顶部有一个分段控制器,它应该在“视频”和“图像”之间切换。视频页面应该使用代码here 在 UIWebView 中加载大约 5 个 youtube 视频。图像视图应包含大约 5 个缩略图,单击时会打开更大的图片。我的问题是我已经尝试了许多不同的方法来实现这一点,但似乎都没有在任何程度上起作用。我在这里寻找的主要内容是推荐的使用分段控制器在两个视图之间切换的方法,以及是否可以从不同的文件(videosView.h/m 和 imagesView.h/m)加载视图。
在 SecondViewController.m 中,我让应用程序使用以下内容响应 UISegmentedController,但我完全不知道这是否接近正确。
- (IBAction)segmentedControlChanged
{
switch (segmentedControl.selectedSegmentIndex)
{case 0:
[self.view addSubview:videosView.view];
[imagesView.view removeFromSuperview];
NSLog(@"1");
break;
case 1:
[self.view addSubview:imagesView.view];
[videosView.view removeFromSuperview];
NSLog(@"2");
break;
default:
break;
}
}
在 videosView.h 中,我只有以下内容:
#import <UIKit/UIKit.h>
@interface videosView : UIWebView
{
}
- (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
@end
在 videosView.m 中,我有以下内容,但我在 initWithFrame 行上收到警告。
- (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;
{
if (self = [super init])
{
// Create webview with requested frame size
self = [[UIWebView alloc] initWithFrame:frame];
// HTML to embed YouTube video
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
// Populate HTML with the URL and requested frame size
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height];
// Load the html into the webview
[self loadHTMLString:html baseURL:nil];
}
return self;
}
@end
imagesView 已制作,但目前没有添加代码,因为我只是想先整理视频。
【问题讨论】:
标签: iphone objective-c ios uiwebview uisegmentedcontrol