相关疑难解决方法(0)

SwiftUI - 表单中的 NavigationLink 单元格在详细信息弹出后保持突出显示

在 iOS 14 中,似乎NavigationLinks 在Form上下文中返回后不会被取消选择。对于Form Pickers 和任何其他导致View列表中另一个的呈现(为呈现单元格提供高亮上下文)也是如此。

我在 iOS 13 中没有注意到这种行为。

一旦其他视图被关闭,有没有办法“取消选择”突出显示的行?

示例代码:

struct ContentView: View {

    var body: some View {
        Form {
            NavigationLink(destination: Text("Detail")) {
                Text("Link")
            } 
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

(不同)示例视觉:

例子

uikit ios swift swiftui

33
推荐指数
5
解决办法
4250
查看次数

我可以调整 UITableViewDelegate 的 didSelectRowAtIndexPath: 吗?

问题是这样的:

我需要能够在具有大量表视图的大型现有应用程序中获取 didSelectRowAtIndexPath 的分析。

我的第一个想法是在 didSelectRowAtIndexPath: 上进行方法调整:但是我的应用程序崩溃并显示“无法识别的选择器发送到实例”消息,具体取决于原始 didSelectRowAtIndexPath 实现中访问的内容。

以下是我尝试在 UIViewController 类别中实现此目的的方法:

#import "UIViewController+Swizzle.h"

@implementation UIViewController (Swizzle)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPathSwizzled:(NSIndexPath *)indexPath {
    NSLog(@"Log something here");
    [self tableView:tableView didSelectRowAtIndexPathSwizzled:indexPath];
}

+ (void) initialize {
    BOOL conformsToTableViewDelegate = class_conformsToProtocol(self, @protocol(UITableViewDelegate));
    if(conformsToTableViewDelegate) {
        Method method1 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPath:));
        Method method2 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPathSwizzled:));
        method_exchangeImplementations(method1, method2);
    }
}


@end
Run Code Online (Sandbox Code Playgroud)

这能实现吗?如果是这样,我做错了什么?

谢谢!

objective-c uitableview uiviewcontroller swizzling ios5

5
推荐指数
1
解决办法
1812
查看次数