2012-11-07 27 views
7

我有一個UIViewController,裏面有3 UIWebView。我以編程方式向左滑動到我的webViews。現在我可以刷卡,但只有3頁,然後重複。我想增加我的currentPage並將其添加到我的webView3,但我不知道該怎麼做。每次刷卡後增加頁面Objective-C

您能否給我一些提示?這部分我真的有問題!

這裏是我的代碼:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
NSLog(@"test view"); 

NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: @"Name/Name1" ofType:@"html" ]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webView2 loadRequest:request]; 
[webView2 bringToFront]; 

    NSURL *url = [NSURL fileURLWithPath:[ [ NSBundle mainBundle ] pathForResource: 
@"Name/Name2" ofType:@"html" ]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webView3 loadRequest:request]; 

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] 
initWithTarget:self action:@selector(swipeLeftAction:)]; 
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; 
swipeLeft.delegate = self; 
[self.view addGestureRecognizer:swipeLeft]; 
} 

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer 
shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer 
*)otherGestureRecognizer 
{ 
return YES; 
} 

當前頁是一個整數,並在開始的時候是0。我的問題是我應該怎麼我的當前頁添加到webView3這樣,當我將其滑增加我的網頁?

- (void)swipeLeftAction:(id)ignored 
{ 
NSLog(@"Swipe Left"); 
UIWebView *temp = webView2 ; 
webView2 = webView3; 
webView3 = webView; 
webView = temp; 

[webView2 bringToFront]; 
currentPage++; 
} 

在此先感謝!

****編輯:**

此當前頁面沒有連接到任何webView的,我怎麼能得到這個增長我的web視圖**

+0

你還在努力解決這個問題嗎? – propstm

回答

0

基於這個職位信息(Does UIGestureRecognizer work on a UIWebView? )它看起來像手勢識別器和網頁瀏覽並不總是一起玩,因爲webview自己的手勢識別器。也許最好的辦法是在你的web視圖中添加鏈接,當你觸摸時使用你自己的方案來增加currentPage

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType { 
    if ([[[inRequest URL] absoluteString] hasPrefix:@"mySchemeIncrementPage:"]) { 
    currentPage++; 
    NSLog(@"CURRENT PAGE COUNT: %i", currentPage); 
    return NO; 
    } 
}