gpt4 book ai didi

ios - 如何在没有 NavigationController 的情况下使用 ASTableNode 在 ASViewController 上添加像 Navigationbar 这样的 headerView?

转载 作者:行者123 更新时间:2023-11-28 17:56:06 24 4
gpt4 key购买 nike

在我的应用程序中,我通常不使用 NavigationController。在 UITableView 中我会这样做,会添加

[Self.view addSubview: self.myCustomHeaderView];

但我正在使用 ASTableNode。如果我做某事,这里类似的事情:

    - (instancetype)init {
_tableNode = [[ASTableNode alloc] init];
self = [super initWithNode:_tableNode];

if (self) {

_tableNode.dataSource = self;
_tableNode.delegate = self;

self.navigationItem = //navigationItem implement
UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
navbar.backgroundColor = [UIColor redColor];

navbar.items = @[self.navigationItem];

ASDisplayNode *navBarNode = [[ASDisplayNode alloc] initWithViewBlock:^UIView * _Nonnull {
return navbar;
}];
[self.node addSubnode:navBarNode];
}

return self;
}

然后这个节点被添加为列表的一部分并与列表一起滚动,我需要它作为固定标题。

最佳答案

init用ASDisplayNode而不是ASTableNode,然后在VC的节点上添加表节点,例如:

@interface OCTextureTableController : ASViewController<ASDisplayNode *>

@property (nonatomic, strong) ASTableNode *tableNode;

- (instancetype)init
{
self = [super initWithNode:[ASDisplayNode new]];
if (self) {
self.tableNode = [[ASTableNode alloc] init];
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.

self.tableNode.backgroundColor = [UIColor yellowColor];
self.tableNode.frame = CGRectMake(0, NAVIGATION_BAR_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-NAVIGATION_BAR_HEIGHT);
[self.node addSubnode:self.tableNode];
}

关于ios - 如何在没有 NavigationController 的情况下使用 ASTableNode 在 ASViewController 上添加像 Navigationbar 这样的 headerView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43447554/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com