6

iPhone 6sにいくつかのテスト3D Touch機能を追加しました。UITableViewController一般的には問題なく動作しますが、2 つの問題を確認できました。何が起こっているのか、それを通常の方法で修正する方法がわかりません。

1)私のセルは選択可能であるため、ユーザーはそれを押すか、「3D Touch」を使用できます。問題は、「Pop」と「Peek」を使用すると選択され、またはメソッドUITableViewCellを使用して通常の方法で選択を解除できないことです。コンプリートでも色々なところで選択解除してみました。それらは何もせず、セルは選択された状態のままです。選択したセルを呼び出す他の一時コードを呼び出して、選択したセルを取得しましたが、これらの方法は機能しませんでした。setSelected:setHighlighted:previewingContext:commitViewControllerpresentViewControllerreviewingContext.sourceView

  • 質問は、ユーザーが「ポップ」プレスを適用したときにセルを選択解除する(または選択しない方がよい)通常の方法はありますか?

2) また、「ポップ」ジェスチャをキャンセルしてセルを初期状態にすると (previewingContext:viewControllerForLocationメソッドが呼び出されていない場合)、UI がハングし、タッチにまったく反応しない場合があることにも気付きました。私はそれを機能させるために殺す必要があります。非常に奇妙に思えますが、このチュートリアルを確認しました。言及されていない問題はありませんが、デリゲートをセルに登録するのではなく、UITableView「ポップ」ジェスチャで tableView 全体を強調表示しますが、セルは強調表示しません。

  • ここで何が間違っている可能性がありますか?

UITableViewController以下に、準拠するテストで3Dタッチを実装する方法を示しますUIViewControllerPreviewingDelegate

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("SomeDemoID",
        forIndexPath: indexPath) as! UITableViewCell

    // Some cell configuration

    if #available(iOS 9.0, *) {
        if traitCollection.forceTouchCapability == .Available {
            self.registerForPreviewingWithDelegate(self, sourceView: cell)
        }
    } else { // Fallback on earlier versions}

    return cell;
}


// MARK: - UIViewControllerPreviewingDelegate

    func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
    {
        // Just Test View Controller
        return UIViewController(nibName: nil, bundle: nil)
    }

    func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController)
    {
        self.presentViewController(viewControllerToCommit, animated: true, completion: nil)
    }

前もって感謝します!

4

3 に答える 3

1

同じ問題に気付きました。重複登録が原因だと思います。フラグを追加すると、問題は修正されました。

試してみてください(Objective-Cを使っているのでSwiftで書き直してください)。

カテゴリを実装する

@interface UITableViewCell (FourceTouchRegistered)

@property (nonatomic, assign) BOOL fourceTouchRegistered;

@end

#import "UITableViewCell+FourceTouchRegistered.h"
#import <objc/runtime.h>

@implementation UITableViewCell (FourceTouchRegistered)

- (void)setFourceTouchRegistered:(BOOL)fourceTouchRegistered
{
    objc_setAssociatedObject(self, @"fourceTouchRegistered", @(fourceTouchRegistered), OBJC_ASSOCIATION_ASSIGN);
}

- (BOOL)fourceTouchRegistered
{
    return [objc_getAssociatedObject(self, @"fourceTouchRegistered") boolValue];
}

@end

それから

    if(cell.fourceTouchRegistered == NO) {
        cell.fourceTouchRegistered = YES;
        if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable) {
            [self registerForPreviewingWithDelegate:self sourceView:cell];
        }
    }
于 2015-12-21T18:15:52.693 に答える
0

プレビュー UIViewController が既にpreviewingContext(_:viewControllerForLocation:)メソッドに表示されているかどうかを確認してください。

何かのようなもの

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController?
{
    if self.navigationController.presentedViewController.isKindOfClass(PreviewViewController) {
        return nil
    }
    return PreviewViewController()
}
于 2015-12-19T10:38:10.413 に答える