自定义tableviewcell.xib未填充表视图



我遇到了一个烦人的问题,我一辈子都找不到。我知道这已经涵盖了,据我所知,我做得很好,但我无法让这个自定义单元格出现在模拟器上。

我在表视图和集合视图方面也遇到了这个问题,我认为两者的结果可以用相同的方式查看,所以如果你能帮助我处理表视图,我将不胜感激。如下:

下面的代码来自ViewController的.m文件,正如您在viewdidload方法中看到的,我已经注册了nib,并给出了重用标识符"tableViewCell"。现在,如果我错了,请纠正我,但我相信我应该将这个标识符赋予故事板中的原型单元,并将xib的重用标识符留空。换句话说,我应该使用"tableViewCell"标识符的唯一位置是用于原型单元格的viewdidload方法和cellforRowAtIndexPath方法,对吧?如果我错过了任何步骤,请让我知道,提前感谢:

#import "headEndChassisViewController.h"
#import "HeadEndChassisTableViewCell.h"
@interface headEndChassisViewController ()
@end
@implementation headEndChassisViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UINib *cellNib = [UINib nibWithNibName:@"headEndChassisCollectionViewCell" bundle:nil];
    [self.headEndChassisCollectionView registerNib:cellNib forCellWithReuseIdentifier:@"headEndCell"];
    UINib *tableViewCellNib = [UINib nibWithNibName:@"HeadEndChassisTableViewCell" bundle:nil];
    [self.headEndChassisTableView registerNib:tableViewCellNib forCellReuseIdentifier:@"tableViewCell"];

    //The code below configures the textviews underneath the CollectionView
    [[self.slotNumberTextView layer] setBorderColor:[[UIColor blackColor] CGColor]];
    [[self.slotNumberTextView layer] setBorderWidth:1];
    [[self.slotNumberTextView layer] setCornerRadius:1];
     self.slotNumberTextView.editable = NO;
    [[self.slotStatusTextView layer] setBorderColor:[[UIColor blackColor] CGColor]];
    [[self.slotStatusTextView layer] setBorderWidth:1];
    [[self.slotStatusTextView layer] setCornerRadius:1];
    self.slotStatusTextView.editable = NO;
    [[self.bandTextView layer] setBorderColor:[[UIColor blackColor] CGColor]];
    [[self.bandTextView layer] setBorderWidth:1];
    [[self.bandTextView layer] setCornerRadius:1];
    self.bandTextView.editable = NO;
    [[self.typeTextView layer] setBorderColor:[[UIColor blackColor] CGColor]];
    [[self.typeTextView layer] setBorderWidth:1];
    [[self.typeTextView layer] setCornerRadius:1];
    self.typeTextView.editable = NO;
    //Code below configures the input power textview corner radius
    [[self.inputPowerTextView layer] setCornerRadius:3.3];
    //Code below configures border for Apply and Reset Buttons
    [[_resetButtonProperty layer]setBorderWidth:1.0f];
    [[_applyButtonProperty layer]setBorderWidth:1.0f];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - Collection View
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 12;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"headEndCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}


#pragma mark - Table View
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tableViewCell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}
- (IBAction)resetButton:(id)sender {
}
- (IBAction)applyButton:(id)sender {
}
@end

这可能是很多事情。

第一,您设置了表视图和集合视图的委托和数据源吗?这通常会被错过(我自己也做过几次)。我在viewDidLoad中没有看到它,所以你必须在你的故事板中看到它。你也没有提到你尝试注销一行的单元格,这让我相信这是问题的根源,考虑到你没有出现错误或崩溃,这是我最好的选择。

第二,可能是你装笔尖的方式。我相信在您的情况下,您不需要在代码中这样做。我认为您可以将UITableView单元格拖到表视图中,设置重用,并在检查器中设置类。如果我装错了笔尖,在这个博客中描述的过去也适用于我。

希望这会有所帮助。

最新更新