0

我创建带有可重用标题的表格视图。当我从 xib 加载标题时,标题发生了一些奇怪的事情

- (UIView*)dequeueReusableHeaderView
{
    NSInteger indexAvailableView = [reusableHeaders indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop)
    { return  [obj superview] == nil; }];

    return (indexAvailableView != NSNotFound)? reusableHeaders[indexAvailableView] : nil;
}

- (void)enqueueReusableView:(UIView*)headerView
{
    [reusableHeaders addObject:headerView];
}

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    BGDiaryHeader *header = (BGDiaryHeader*)[self dequeueReusableHeaderView];
    if (!header) {
        UINib *headerNib = [UINib nibWithNibName:@"BGDiaryHeader_iPhone" bundle:nil];
        NSArray *aNib = [headerNib instantiateWithOwner:self options:nil];
        BGDiaryHeader *header = [aNib objectAtIndex:0];

    //if simple [[_ alloc]init] all works fine
    //    header = [[BGDiaryHeader alloc] init];
        [self enqueueReusableView:header];
    }
    //set display data
    return header;
}

如果我在代码中创建标题视图,一切正常

4

1 回答 1

0

if块中的标头阴影

-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
    BGDiaryHeader *header = (BGDiaryHeader*)[self dequeueReusableHeaderView];
    if (!header) {
        UINib *headerNib = [UINib nibWithNibName:@"BGDiaryHeader_iPhone" bundle:nil];
        NSArray *aNib = [headerNib instantiateWithOwner:self options:nil];
        header = [aNib objectAtIndex:0];

        [self enqueueReusableView:header];
    }
    //set display data
    return header;
}
于 2013-02-28T06:06:50.767 回答