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

标签 ios objective-c asyncdisplaykit

在我的应用程序中,我通常不使用 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/

相关文章:

ios - ASyncDisplayKit - 一个容器中的多个节点

css - 摆脱 iOS 网络应用程序中的放大镜

ios - Swift 3 和 Firebase 观察 Child 是否存在

ios - 获取当前注释信息以显示在 xamarin iOS 的 View 中

objective-c - 如何更正 "Undefined symbols for architecture i386: "_main"链接问题?

ios - 表格 View 单元格高度

ios - post方法如何只发送必需的参数objective-c

ios - 归档我的项目时,“无法导入桥接头”, 'file not found'

ios - iPhone/iOS 中 viewDidAppear、viewDidLoad 之间的区别?

swift - 有没有办法在 ASCollectionNode 水平滚动上加载更多内容时插入新项目