UIViewController 内に UITableView があり、セットアップに必要なすべての手順を実行したと思いますが、プロトコルの必要なメソッド内に NSLog を配置すると、tableView から応答がありません
UITableView に、そのプロトコルを実装することを伝えます
@interface SubSelectionTableViewWithMenuVC : UIViewController <CustomTableViewCellDelegate,
UITableViewDelegate,
UITableViewDataSource,
TableViewModelDelegate>
ヘッダーにtableViewアウトレットを設定しました
@property (weak, nonatomic) IBOutlet UITableView *tableView;
ViewDidLoad
デリゲートを自分自身に設定します。
self.tableView.delegate = self;
self.tableView.dataSource = self;
そして、必要なデリゲート メソッドを実装します
– tableView:cellForRowAtIndexPath:
– tableView:numberOfRowsInSection:
しかし、何も起こりません。tableView オブジェクトの ViewDidLoad で NSLog を実行すると、次のように表示されます。
tableView: <UITableView: 0x1d43aa00; frame = (0 0; 0 0); clipsToBounds = YES;
autoresize = TM+BM; gestureRecognizers = <NSArray: 0x1cdc54f0>; layer = <CALayer:
0x1cdc5350>; contentOffset: {0, 0}>
必要なデリゲート メソッド:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"num of sections");
return 1;
}
#pragma mark - UI set cell contents
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cell for row at indepath");
static NSString *CellIdentifier = CELL_IDENTIFIER_LECTURES;
CustomTableViewCell *cell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.indexPath = indexPath;
cell.delegate = self;
// Configure cell
[cell.mainLabel setText:[self titleForRow:indexPath.row]];
[cell.numberLabel setText:[NSString stringWithFormat:@"%i", indexPath.row + 1]];
cell.state = [self restoreTagButtonStateForCell:cell];
// perform selector on cell to update and show its last stored state
if ([cell respondsToSelector:@selector(updateButtonImageState)]) {
[cell performSelector:@selector(updateButtonImageState)];
} else {
[NSException raise:NSGenericException format:@"cell does not respond to selector"];
}
// Setting the Highligthed color of selected cell
UIView *goldenColor = [[UIView alloc] init];
goldenColor.backgroundColor = [UIColor colorWithRed:0.824 green:0.749 blue:0.553 alpha:1.0f];
cell.selectedBackgroundView = goldenColor;
return cell;
}