Contacts(TableViewController)报错总结

1. mock网络问题

问题:mock网络的JSON数据无法获取

  • 提示:mock请求出错:mock....7777
  • 原因:mock请求时获取ip地址失败。
  • 修改方法:serviceProvider脚本中的获取ip方法语句改为
ifconfig | grep "inet " | grep -Fv 127.0.0.1 | awk '{print $2}'

2.TableViewCell

问题:返回cell为nil

  • 出错提示如图:


    错误1.png
    错误1.png

    Assertion failure in -[UITableView configureCellForDisplay:forIndexPath:]......

  • 出错原因:没有register cell 的 identifier@“getContact"
    Because cellForRowAtIndexPath is returning a nil value and then configureCellForDisplay is expecting a UITableViewCell. The storyboard or XIB does not have a cell defined with the cell identifier you specified. Better check the spelling of identifier.

  • 解决:
    register方法:UITableView registerClass:

- (void)registerClass:(nullable Class)cellClass forCellReuseIdentifier:(NSString *)identifier NS_AVAILABLE_IOS(6_0);

tableView调用方法register:

 [self.tableView registerClass:[ContactsTableViewCell class] forCellReuseIdentifier:@"ContactsTableViewCell"];

提示:register应该在tableView初始化之后:

self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
[self.tableView registerClass:[ContactsTableViewCell class] forCellReuseIdentifier:@"ContactsTableViewCell"];

问题:cell添加到父视图

  • 出错提示:failure in configureCellForDisplay:forIndexPath....
  • 出错原因:cell的view(checkContainerView)没有作为子视图添加到父视图contentView中。同时添加约束要在addSubview之后,否则会导致崩溃。
  • 解决:在子视图创建后,addSubView
    _checkContainerView = [UIView new];
    [self.contentView addSubview:_checkContainerView];

问题:cell创建失败

  • 出错提示:failure in configureCellForDisplay:forIndexPath....
  • 出错原因:方法缺少参数:forIndexPath
  • 解决:补上参数
ContactsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ContactsTableViewCell" forIndexPath:indexPath];

3、数据类型

问题:数据类型出错

  • 出错提示failure in -[_NSCFNumber methodSignatureForSelector:]

  • 出错原因:返回的数据类型与控件所需要的数据类型不符,此处为JSON中数据类型为Number,但绑定的控件所需的数据类型是NSString。(提示:JSON文件中的string 要加双引号。)

  • 解决:把 JSON中认定是string的value加上双引号。

{"contactName": "Tom2",
                        "contactId": "1473490800002",
                        "contactNumber": "1473307200002",
                        "contactAdd":"杭州"}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 翻译自“Collection View Programming Guide for iOS” 0 关于iOS集合视...
    lakerszhy阅读 3,918评论 1 22
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,198评论 4 61
  • 这个冬天是否会下雪,是否有人主动来问我一句你冷吗,是否会有个幸福的圣诞夜,是否我还会爱你,是否我的心会...
    _怀旧阅读 205评论 0 0
  • 这是我在简书上写的第一篇文章,0:24的时间,与熟睡的女儿同在一房间,在漆黑中慢慢地打着字,因为敲键盘的力度得控制...
    Joyce臭臭阅读 697评论 2 1
  • 也许 相遇是为了分离 分离 是为了更好的相聚 但 我们的人生才刚刚开始 因为 一切都是未知数 再一个夏天 教室...
    酒巷醉人阅读 94评论 0 0