2016-03-04 31 views
0

我有一個嵌套滾動視圖(水平分頁滾動視圖內的垂直分頁滾動視圖)的UIButton。我的問題是,當我點擊它突出顯示的按鈕時,它不會觸發我已將它鏈接到的一個繼續。然後我嘗試將它鏈接到一個IBAction函數,在該函數中放置了一個斷點,當我點擊按鈕時我沒有觸及該斷點,所以我的按鈕也沒有觸發IBActions。UIButton內嵌滾動視圖是突出顯示,但不觸發Segue或IBAction點擊時 - Swift

我試過關閉拖延內容觸及兩個滾動視圖,並沒有奏效。所做的只是讓我點擊按鈕時突出顯示按鈕,而不是在突出顯示前加重一點。無論哪種方式,當我點擊按鈕時,我的按鈕會突出顯示,但我的任何插件(segues或IBActions)都沒有觸發,我認爲這很奇怪。我發現其他人在網上遇到類似的問題,但他們的按鈕甚至沒有突出顯示。我的亮點,所以我知道它從用戶獲得輸入。

這裏是我如何實例化嵌套的滾動視圖。主水平滾動視圖創建在我的故事板中,然後在其ViewController viewDidLoad方法中,我這樣做嵌套垂直滾動視圖。垂直滾動視圖是包含我的按鈕。

let readingVC = storyboard!.instantiateViewControllerWithIdentifier("ReadingViewController") as! ReadingRingViewController 
readingVC.read = reading.minutesRead 
readingVC.goal = reading.minutesGoal 
readingVC.selectedDate = selectedDate 
readingVC.today = today 
let readingView = readingVC.view 
let scrollPage2 = UIScrollView(frame: CGRectMake(readingView.bounds.size.width,0,readingView.bounds.size.width, readingView.bounds.size.height)) 
scrollPage2.addSubview(readingView) 
scrollPage2.contentSize = CGSize(width: readingView.bounds.size.width, height: readingView.bounds.size.height*2) 
scrollPage2.pagingEnabled = true; 
scrollPage2.alwaysBounceVertical = true 
scrollPage2.userInteractionEnabled = true 
let readingBottomView = storyboard!.instantiateViewControllerWithIdentifier("ReadingBottomViewController").view 
let scrollPage2Bottom = UIScrollView(frame: CGRectMake(0,readingView.bounds.size.height,readingBottomView.bounds.size.width, readingBottomView.bounds.size.height*2)) 
scrollPage2Bottom.addSubview(readingBottomView) 
     scrollPage2Bottom.contentSize = CGSize(width: readingBottomView.bounds.size.width, height: readingBottomView.bounds.size.height) 
scrollPage2.addSubview(scrollPage2Bottom) 
scrollPage2.sendSubviewToBack(scrollPage2Bottom) 

下面是的viewController的代碼,我的按鈕。我已經將它連接到IBAction爲並且還鏈接到其他的viewController作爲推動賽格瑞

回答

4

我解決了我自己題。該按鈕的操作不起作用的原因是因爲我添加了按鈕作爲子視圖的視圖,但卻忘記了將按鈕視圖的視圖控制器作爲子視圖控制器添加。所以,我插線以下的代碼行我實例化readingVC後,並設置它的成員變量:

self.addChildViewController(readingVC) 
readingVC.didMoveToParentViewController(self) 

現在該按鈕的工作原理完全如預期

+0

它的工作就像一個魅力!十分感謝!!!在Objective-C中:[self addChildViewController:viewController]; [viewController didMoveToParentViewController:self]; [scrollView addSubview:viewController.view]; –