gpt4 book ai didi

ios - 尝试在 iOS 中动态调整 UITableView 的大小时出现运行时异常

转载 作者:行者123 更新时间:2023-11-29 01:34:46 24 4
gpt4 key购买 nike

每当用户向表中添加新行时,我都会尝试增加 UITableView 的高度。该代码允许用户成功地将行添加到 tableView 没有问题,但是,当我尝试使用它调整表格的高度时出现运行时异常。

这是我的代码:

- (IBAction)addRow:(id)sender {

...

CGFloat maxDynamicTableHeight = 250.0f;
NSInteger numberOfSections = [self numberOfSectionsInTableView:self.myTable];
CGFloat runningHeight = 0.0f;

for (int section = 0; section < numberOfSections && runningHeight < maxDynamicTableHeight; section++) {
NSInteger numberOfRows = [self tableView:self.myTable numberOfRowsInSection:section];
for (int row = 0; row < numberOfRows && runningHeight < maxDynamicTableHeight; row++) {
NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:section];
NSLog(@"what is my path object? %@", path);
runningHeight += [self tableView:self.myTable heightForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:section]];
}
}

CGRect frame = self.choiceTable.frame;
frame.size.height = (runningHeight > maxDynamicTableHeight) ? maxDynamicTableHeight : runningHeight;
self.myTable.frame = frame;
}

我还在我的代码中做的是输出 NSIndexPath 对象以查看它是否有效,这就是我得到的:

what is my path object? <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}

我得到的运行时异常是:

[MyViewController tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x7f9d306aadb0 2015-10-12 01:02:09.300 munch[27412:5036398] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyViewController tableView:heightForRowAtIndexPath:]: unrecognized selector sent to instance 0x7f9d306aadb0' * First throw call stack:

谁能看出我做错了什么?

最佳答案

异常告诉你你的 TableView 数据源没有实现方法 tableView:heightForRowAtIndexPath:

如果你实现了这个方法那么异常就会消失

关于ios - 尝试在 iOS 中动态调整 UITableView 的大小时出现运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33089696/

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