• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 无法在 UITableviewCell 中选择行

[复制链接]
菜鸟教程小白 发表于 2022-12-13 08:23:18 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

friend ,我一直在尝试在我的 UITableView 单元格中设置默认复选标记,这是我的代码,请看一下,我很难得到我想要的输出

-(UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath {
NSString *cellIdent = @"cell1111";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdent];
if (tableView==_ShapeSelectionTable)
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [_ShapeSelectionTable dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }

    if([_selectedShapeArray containsObject:[_shapeArray objectAtIndex:indexPath.row]] || [_selectedShapeArray containsObject"Check All"]) {

        cell.accessoryType = UITableViewCellAccessoryCheckmark;

    }
    else
    {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
  for (NSString *s in _shaperesultArray)
    {
        for (int i=0; i<self.shapeArray.count; i++)
        {
        NSIndexPath *myIdx=[NSIndexPath indexPathForRow:i inSection:0];
         ShapeInfo *shap=[self.shapeArray objectAtIndex:i];


            if ([shap.shape isEqualToString:s])
            {


                cell = [[self ShapeSelectionTable] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
                cell.accessoryType=UITableViewCellAccessoryCheckmark;
 //[tableView selectRowAtIndexPath:myIdx animated:TRUE scrollPosition:UITableViewScrollPositionNone];
 }
            else
            {
                cell.accessoryType=UITableViewCellAccessoryNone;
            }

        }
    }
 ShapeInfo *shap=[_shapeArray objectAtIndex:indexPath.row];

    cell.textLabel.text=shap.shape;

    return cell;
}

我想从我的 ResultInfo 得到以下输出,Cell 应该记住附件类型 enter image description here

friend 们,我的 JSON 对象中的 preCheckmark(Cell Accessory) 遇到问题 注意我正在以 JSON 格式从 Web 获取该输出 任何帮助将不胜感激..谢谢

更新当我运行此代码时出现异常 -[UITableView _configureCellForDisplay:forIndexPath:],/SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:6509 中的断言失败 2014-06-24 14:14:24.306 TheGemHubApp[2405:60b] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 数据源必须从 tableView 返回一个单元格:cellForRowAtIndexPath:”**

enter image description here



Best Answer-推荐答案


2935.137/UITableView.m:6509 2014-06-24 14:14:24.306 TheGemHubApp[2405:60b] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'*

这个异常发生在这行代码

 cell = [[self ShapeSelectionTable] cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

您应该在此处设置一些断点并模拟正在发生的事情。

关于ios - 无法在 UITableviewCell 中选择行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24381935/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap