我在 UIViewController 中有一个 UITableView,我想我已经完成了所有必要的步骤来设置它,但是当我将 NSLog 放在它的协议的所需方法中时,我没有得到 tableView 的响应
我告诉 UITableView 我将实现它的协议
@interface SubSelectionTableViewWithMenuVC : UIViewController <CustomTableViewCellDelegate,
UITableViewDelegate,
UITableViewDataSource,
TableViewModelDelegate>
我在标题中设置了 tableView 插座
@property (weak, nonatomic) IBOutlet UITableView *tableView;
在ViewDidLoad
我将委托设置为 self.
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;
}