簡體   English   中英

自定義tableviewcell.xib不填充tableview

[英]custom tableviewcell.xib not populating tableview

我遇到了一個煩人的問題,我一生都無法發現。 我知道這已被覆蓋,據我所知,我已經做了一切正確但我不能讓這個自定義單元格顯示在模擬器上。

我有一個表視圖和集合視圖這個問題,我認為兩者的結果可以同樣的方式,所以如果你可以幫我看表視圖,我將不勝感激。 開始:

以下代碼來自View Controller的.m文件,正如您在viewdidload方法中看到的那樣,我已經注冊了nib並給出了重用標識符'tableViewCell'。 現在糾正我,如果我錯了,但我相信我應該將這個標識符提供給storyboard中的原型單元格,並將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

這可能是很多事情。

1您是否設置了表視圖和集合視圖的委托和數據源? 這常常被遺漏(自己做了幾次)。 我在viewDidLoad中看不到它,因此您必須在情節提要中完成它。 您沒有提到您嘗試注銷行的單元格,這使我相信這是問題的根源,並且假設您沒有收到錯誤或崩潰這是我最好的選擇。

第二,它可能是你如何加載你的筆尖。 我相信你不需要在代碼中執行此操作。 我想你可以將UITableView單元格拖到表視圖中,設置重用,並在檢查器中設置類。 如果我如博客所述錯誤地裝入筆尖,過去也對我有用。

希望能有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM