gpt4 book ai didi

ios - 在 ViewController 中设置了 TableView 的数据源和委托(delegate),但没有任何反应

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:40:56 25 4
gpt4 key购买 nike

我在 UIViewController 中有一个 UITableView,我想我已经完成了所有必要的步骤设置它,但是当我把一个 NSLog 放在它的协议(protocol)的 requiered 方法中时,我没有得到 tableView 的响应

enter image description here

我告诉 UITableView 我将实现它的协议(protocol)

@interface SubSelectionTableViewWithMenuVC : UIViewController <CustomTableViewCellDelegate,
UITableViewDelegate,
UITableViewDataSource,
TableViewModelDelegate>

我在标题中设置了 tableView socket

@property (weak, nonatomic) IBOutlet UITableView  *tableView;

ViewDidLoad 中,我将委托(delegate)设置为 self。

self.tableView.delegate = self;
self.tableView.dataSource = self;

然后我实现了所需的委托(delegate)方法

– 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}>

必需的委托(delegate)方法:

- (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;
}

最佳答案

原因是因为您没有实现– tableView:numberOfRowsInSection: 方法。实现此方法并返回您需要的金额。

关于ios - 在 ViewController 中设置了 TableView 的数据源和委托(delegate),但没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18477661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com