カスタム セル クラスを作成せずにカスタム セルを作成します。私はこれが可能であることを知っています。ストーリーボードに、ラベル付きのプロトタイプ セルを持つ tableviewcontroller を作成しました。属性で、セル名「mycell」を設定しました。そして、私が使用したコードは次のとおりです。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *CellIdentifier = @"mycell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];}
UILabel *title = (UILabel*) [cell viewWithTag:1];
title.text = @"Hi";
return cell;
}
しかし、アプリを実行すると、ラベルの付いたセルのない空のテーブルしか表示されません。私が使用したtableViewメソッドでは:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1;}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 5; }
ありがとうございました。