2015-02-11 81 views
0

我遇到了一个恼人的问题,我不能为我的生活发现。我知道这已被覆盖,据我所知,我做的一切正确,但我不能让这个自定义单元显示在模拟器上。自定义tableviewcell.xib不填充tableview

我这个问题的表视图和集合视图,以及我的结果可以看到两个相同的方式,所以如果你可以帮助我与表视图它将不胜感激。这里有:

以下代码来自View Controller的.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 
+0

'cellNib'最终是否为零?如果这样做意味着它找不到你的笔尖。 xib中的单元格是“UITableViewCell”的子类吗?如果不是,那么它将无法将其出队。 xib'tableViewCell'中的重用标识符是否相同?如果不是,它将无法将其出队。 – InkGolem 2015-02-11 23:46:18

回答

0

这可能是一些事情。

1您是否设置了表视图和集合视图的委托和数据源?这通常会错过(自己做几次)。我没有在viewDidLoad中看到它,所以你必须在故事板中完成它。你没有提到你尝试登出行的细胞,这导致我相信这是问题的根源,并且鉴于你没有得到错误或崩溃,这是我最好的选择。

第二它可能是如何加载你的笔尖。我相信你不需要在代码中这样做。我认为你可以将一个UITableView单元格拖入你的表格视图,设置重用,并在督察中设置类。如果我错误地按this中描述的加载笔尖,博客也为我工作过去。

希望能有所帮助。

+0

哇我觉得自己像一个白痴,原来是设置数据源和代表。谢谢你,先生。 – Ayman 2015-02-12 20:24:04

+0

就像我说过的那样,我经常会错过,而且我自己做了很多次。很高兴我能够提供帮助。 – 2015-02-12 20:27:41