對不起,長期的問題,但我一直堅持這幾天,並用盡所有其他幫助。UISegmented控制器加載一個視圖與幾個Youtube UIWebViews和另一個視圖與圖像
目前,我有一個帶有四個選項卡的選項卡欄應用程序。在第二個選項卡(SecondViewController)中,我在頂部有一個應該在「視頻」和「圖像」之間切換的分段控制器。視頻頁面應該包含5個使用代碼here在UIWebView中加載的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是製作好的,但是目前沒有添加代碼,因爲我只是想先把視頻整理出來。
1.你是否建議我在我的SecondViewController.h中定義UIView * videosView? 2.我會如何將你的第一次建議連接起來? 3.我將如何去做這件事? 4.這是我聽說過的第一個,我會試圖做到這一點。 5.我不完全理解你的意思。你可能會說,我沒有經驗豐富的程序員附近,並感謝我能得到的所有幫助。 – 2011-12-13 23:19:27