如何将xib的子视图显示为来自另一个xib的表单元格负载

时间:2013-02-14 10:30:53

标签: objective-c uitableview xib subview

我有加载xib子视图[TestSummaryView]到xib文件加载到表格单元[NotesTableCell]中的问题。只有在通过拖出屏幕刷新单元格后,我的xib子视图才可见。

MainFile.m:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{

NotesTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"NotesTableCell"];
if (cell == nil) 
{
    [[NSBundle mainBundle] loadNibNamed:@"NotesTableCell" owner:self options:nil];
    cell = __noteTableCell;
    self.__noteTableCell = nil;
}

(...)

for (UIView* view in [cell.summaryView subviews])
    [view removeFromSuperview];

UIView* view = [note.form summaryView];
[cell.summaryView addSubview:view];
view.bounds = cell.summaryView.bounds;
view.center = CGPointMake(cell.summaryView.bounds.size.width/2, cell.summaryView.bounds.size.height/2);

[cell.webView setHidden:YES];
[cell.summaryView setHidden:NO];                               
}

TestForm.m

-(UIView*)summaryView 
{
if (!_testSummaryView) 
{
    NSArray* xib = [[NSBundle mainBundle] loadNibNamed:@"TestSummaryView" owner:self options:nil];
    _testSummaryView = [[xib objectAtIndex:0] retain];
}

(...)

return _testSummaryView;
}

1 个答案:

答案 0 :(得分:0)

问题解决了。这是代码的其他部分。