objective-c - cellForRowAtIndexPath 忽略部分
问题描述
在我的 UITableViewController 中,我定义了 3 个部分。但是,如果我想访问 cellForRowAtIndexPath 方法中比第一个方法更多的部分,这将被忽略。例如,如果我想在第二部分添加一行。有没有人有解决这个问题的办法?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if (indexPath.row == 0) {
..
return cell;
}
if (indexPath.row == 1) {
..
return cell;
}
if (indexPath.row == 2) {
..
return cell;
}
}
if (indexPath.section == 1) {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:aufgabe];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aufgabe];
}
[cell.textLabel setText:@"Test"];
}
}
else if (indexPath.section == 2) {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:geraet];
return cell;
}
return nil;
}
解决方案
有趣的!我为自己修好了。我必须填写 numberOfRowsInSection 方法。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 3;
}
if (section == 1) {
return 5;
}
else {
return 0;
}
}
推荐阅读
- oracle - Oracle 中的自定义日期格式
- javascript - 来自 Gsheet 的 html 文件中的 Google Apps 脚本动态表格行
- node.js - 外部 API 调用服务器还是客户端?
- vue.js - Vue-formulate - 分组项目可折叠/切换折叠
- typo3 - 在typo3中维护hreflang外部页面
- node-modules - 如何使用带有动态参数的“google-charts-node”npm 包
- python - 不同 git 存储库中 python 脚本之间的接口
- python - 如何使用 python 在 selenium 中安装特定于本地 chrome 浏览器版本的 chromedriver?
- javascript - 使用 Javascript 解构时,是否有任何简洁的方法可以将默认值设置为 null
- django - DRF 如何更改 JSON 响应中的字段键名