2014-01-08 63 views
1

我在這裏有一些構造;當touchesBegin碰到UITableViewCell時,我擴展了UITableViewCell,並在UITableViewController類中以模態方式顯示UIViewController。當touchesEnded命中時,我再次刪除此UIViewControllerUITableViewCell的touchesEnded在頂部顯示ViewController時沒有調用

因此,當您觸摸單元格時顯示內容,當您釋放屏幕時,我再次隱藏它。一切都很好,但如果我快速按下並釋放UITableViewCell,它就不起作用;在這種情況下,不調用touchesEnded。如果我堅持一秒或更長時間,系統工作正常。 'touchesCledlled'也不會被調用。

對此有何看法?由於焦點位於UITableViewCell,所以新顯示的UIViewController或現有的UITableViewController的觸摸方法也不會觸及(直到我釋放並再次按下,但是這違背了目的)。

相關的代碼:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [super touchesBegan:touches withEvent:event]; 

    amDisplayingCapture = YES; 
    [self.showCaptureDelegate displayCapture:self.capture]; 
} 

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [super touchesEnded:touches withEvent:event]; 
    if(amDisplayingCapture) 
    { 
     [self.showCaptureDelegate endDisplayCapture]; 
     amDisplayingCapture = NO; 
    } 
} 

(該UITableViewdidSelectRowAtIndexPath不叫要麼一旦我出現新UIViewController,所以不能使用)

回答

3

從UIResponder頭文件:

您的響應者將收到它正在處理的每個觸摸的touchesEnded:withEvent:touchesCancelled:withEvent:(觸摸它接收d在touchesBegan:withEvent:)。 您必須處理取消的觸摸以確保應用程序中的行爲正確。不這樣做很可能導致不正確的行爲或崩潰。

摘要:您還應該實施touchesCancelled:withEvent:

+0

這裏有更多的信息在這裏:https://developer.apple.com/library/ios/documentation/uikit/reference/UIResponder_Class/Reference/Reference.html –

+0

謝謝,但我應該提到touchesCancelled不叫。不在我期望的UITableViewCell中,而不在其他ViewControllers中。 這就像touchesBegan被調用,但隨後消失無蹤。 – Yasper

+0

所有觸摸都應該結束或取消。是否有可能覆蓋這些方法的子視圖? –

1

如果有人有類似的情況,我通過添加新的viewcontroller的視圖作爲子視圖而不是以模態方式呈現整個viewcontroller來解決這個問題。這似乎允許touchesEnded被調用。

相關問題