arsenium
arsenium

Reputation: 571

How to add headerView like Navigationbar on ASViewController with ASTableNode without NavigationController?

In my application, I do not use the NavigationController, in general. In UITableView I would do so, would add

[Self.view addSubview: self.myCustomHeaderView];

But I'm using ASTableNode. If I do something, something similar here:

    - (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;
    }

Then this node is added as part of the list and scrolled along with the list, and I need it to be as fixed header.

Upvotes: 1

Views: 522

Answers (2)

无夜之星辰
无夜之星辰

Reputation: 6158

initWith ASDisplayNode rather than ASTableNode,then add table node on VC's node,for example:

@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];
}

Upvotes: 0

Ajjjjjjjj
Ajjjjjjjj

Reputation: 675

(i) take Class A as base Class. (ii) take Class B as derived Class having type of class A.

Now in class A Add a uiview on top. that will be considered as navigation.(do anything in that view)

To use same navigation bar: you have to take other all classes as having type of class A.

that's it.

Upvotes: -2

Related Questions