2017-07-11 3 views
-1

私の問題はセルが作成されていますが、initメソッドが呼び出されないことです。xibは使用しません。TableViewカスタムセルはinitメソッドを入力しません

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    _tabV = [[UITableView alloc]initWithFrame:self.view.bounds]; 
    [_tabV registerClass:[TestCell class] forCellReuseIdentifier:@"Cell"]; 
    _tabV.delegate = self; 
    _tabV.dataSource = self; 


    [self.view addSubview:_tabV]; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 10; 
} 


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    return 100; 
} 

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

    TestCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 


    return cell; 

} 

とセル:ここに私の簡単なコードである

- (instancetype)init{ 
    if (self = [super init]) { 
     self.contentView.backgroundColor = [UIColor redColor]; 
    } 
    return self; 
} 


- (instancetype)initWithFrame:(CGRect)frame{ 
    if (self = [super initWithFrame:frame]) { 
     self.contentView.backgroundColor = [UIColor greenColor]; 
    } 
    return self; 
} 

が、いずれかの[INIT]または[initWithFram]と呼ばれました。それは私が考える非常に単純な問題です。しかし、どこが間違っているのか分かりません...

+0

'UITableViewCell'の指定イニシャライザは、[initWithCoder:]である(https://developer.apple.com/documentation/uikit/uitableviewcell/1623220-initwithcoder?language=objc)と[initWithStyle:reuseIdentifier:](https://developer.apple.com/documentation/uikit/uitableviewcell/1623276-initwithstyle?language=objc)。だからあなたはあなたが言及した呼び出しのいずれかを期待していません。 – nayem

+0

ああ...私は正常なビューとして細胞を見て...あなたは正しいです。ありがとうございます。 – Neko

答えて

関連する問題