user3564554
user3564554

Reputation: 11

Need to add a view as TableHeader?

Is it possible to load a View of height 672 as TableView header?I added it But i am not able to scroll and See the tableview cell Details. i have used the code

ACCRemainderView *header =  [ACCRemainderView customHeaderView];

[self.tableView setTableHeaderView:header];

In the Remainder View

+ (id)customHeaderView
{
    ACCRemainderView *customView = [[[NSBundle mainBundle] loadNibNamed:@"ACCRemainderView" owner:nil options:
                                     nil] lastObject];

    //make sure customView is not nil or the wrong class!        
    if ([customView isKindOfClass:[ACCRemainderView class]]) {
        return customView;
    } else {
        return nil;
    }
}

Upvotes: 1

Views: 61

Answers (2)

nmh
nmh

Reputation: 2503

Set tableHeaderView is the best choice. I tested and it works.

ViewForHeaderInSection can not because at this view header's height is larger than table's height.

You can not scroll, I think your tableView is overlap by another view.

- (void)viewDidLoad
{
[super viewDidLoad];

_tableView.dataSource = self;
_tableView.delegate = self;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *title=[self tableView:tableView titleForHeaderInSection:section];
if ( !title )
    return nil;


UIView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 500)];
view.backgroundColor = [UIColor greenColor];
return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 500;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"abcd";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"a";
return cell;
}

Upvotes: 0

Cezar
Cezar

Reputation: 56362

Try implementing - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section in your UITableViewController and return [ACCRemainderView customHeaderView].

Upvotes: 1

Related Questions