![](/img/trans.png)
[英]Why is it that sometimes my web application does not work on the iPhone?
[英]Why does UITableView's swipe delete sometimes work fine & sometimes not?
我的視圖上有一個UITableView
,我想應用特定部分的滑動刪除模式行。 我實施的內容如下:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">> canEditRowAtIndexPath");
if (indexPath.section == CanDeletedSection) {
return YES;
}else{
return NO;
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">> editingStyleForRowAtIndexPath");
if (indexPath.section == CanDeletedSection) {
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">> commitEditingStyle");
if (editingStyle == UITableViewCellEditingStyleDelete) {
// dosomething
}
}
但是當我滑動表格行時,有時會出現“ Delete
按鈕,有時則不會。 順便說一下,我的單元格是自定義的,並且繼承自UITableViewCell
。
我已經將NSLog
添加到上面的方法中。 當Delete
按鈕沒有出現時,我得到的日志如下:
>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath
出現“ Delete
按鈕時,日志如下:
>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath
>> editingStyleForRowAtIndexPath
>> canEditRowAtIndexPath
>> canEditRowAtIndexPath
>> editingStyleForRowAtIndexPath
我做了一個使用自定義單元格的演示,它工作正常。 所以問題是由包含表視圖的視圖控制器引起的。 視圖控制器繼承自另一個視圖控制器,在該視圖控制器中,有一個用於隱藏鍵盤的輕擊手勢。 但是當我從視圖控制器中刪除它們時,結果是一樣的。
請檢查視圖或超級視圖是否有任何其他手勢。 如果是這樣,請確保在設置手勢委托后實現以下UIGestureRecognizerDelegate
方法:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
有時,特別是在模擬器中,很難正確執行滑動。 您會發現它很可能是物理問題,而不是編碼問題。
此外,您可能想要檢查自定義單元格是否包含捕獲滑動的元素,並且不將其傳遞給單元格。
我也面臨同樣的問題......但最后我得到了解決方案: -
例:-
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
如果您使用“commitcommiteditingstyle”,則必須禁用該特定視圖中的任何其他手勢。
希望對你有幫助... :)
視圖層次結構中其他位置的手勢識別器可以攔截和阻止滑動操作。
我在視圖控制器中使用此類別解決了它:
@interface UIView (CellSwipeAdditions)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer;
@end
@implementation UIView (CellSwipeAdditions)
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
@end
感謝bademi帶領我這個解決方案!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.