0

我正在研究从情节提要文件中加载的 Tableview 控制器。

出于可重用性的目的,我希望情节提要中的一个单元格从 nib 文件加载。

我怎样才能做到这一点?

我当前的实现只使用 viewDidLoad 并且没有使用其他 tableview 委托方法

- (void) viewDidLoad
{

    [super viewDidLoad];

     self.title = self.requestTypeDescription;

self.itemDescriptionLabel.text = self.currentItem.articleDescription;
    self.modelNumberLabel.text = self.currentItem.partNumber;

  notesHistoryString =  @"Valerie is a young woman who lives...";
    self.partNumberCell.count.text = [NSString stringWithFormat:@"%@", self.currentItem.sapCount];
    self.serialNumbersCell.count.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.currentItem.serialNumbers.count];



}
4

2 回答 2

0

我最终在故事板中为 Tableview 控制器(TVC)中的 tableview 创建了一个空白单元格。然后我为 UIView 创建了一个 nib 文件。

正在加载 nib 的我的视图具有 initWithFrame(用于加载 xib),其实现如下所示:

    @implementation SimpleView

    -(id)initWithFrame:(CGRect)frame
    {

        NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SimpleView"
                                                              owner:nil
                                                            options:nil];

        if ([arrayOfViews count] < 1){
            return nil;
        }

        SimpleView *newView = [arrayOfViews objectAtIndex:0];
        [newView setFrame:frame];
        self = newView;

        return self;

    }

然后在 TVC 内的 viewDidLoad 上,我将其添加到空白单元格中,如下所示:

@implementation ExistingRequestsItemDetailActionVC




#pragma mark - Life cycle
- (void) viewDidLoad
{

    [super viewDidLoad];

     self.title = self.requestTypeDescription;

self.itemDescriptionLabel.text = self.currentItem.articleDescription;
    self.modelNumberLabel.text = self.currentItem.partNumber;

  notesHistoryString =  @"Valerie is a young woman who lives...";
    self.partNumberCell.count.text = [NSString stringWithFormat:@"%@", self.currentItem.sapCount];
    self.serialNumbersCell.count.text = [NSString stringWithFormat:@"%lu", (unsigned long)self.currentItem.serialNumbers.count];

// Here is where I am loading the other cellview from xib


    SimpleView *myView = [[SimpleView alloc] initWithFrame:self.myCell.bounds];

    myView.slider.value=1;

    [self.myCell addSubview:myView];


}
于 2013-08-08T18:21:01.777 回答
0

使用 registerNib:forCellReuseIdentifier: 注册笔尖:(在 viewDidLoad 中是一个好地方),并在您的 cellForRowAtIndexPath 中,当您需要该类型的单元格时,将具有您传递给该方法的相同标识符的单元格出列。

于 2013-08-08T01:21:27.257 回答