【问题标题】:crash when calling cellForRowAtIndexPath调用 cellForRowAtIndexPath 时崩溃
【发布时间】:2014-08-05 09:45:21
【问题描述】:

当调整包含UITableViewUIView的位置时,会调用以下tableview数据源方法:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath

但是当这个方法被调用时:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    CommentCell *cell = [[CommentCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    NSDictionary *dic = self._tableViewData[indexPath.row];
    [cell setComment:[dic objectForKey:@"text"]];
    [cell setTimeString:[self commentTimeTransfer:[dic objectForKey:@"create_at" ]]];
    [cell setNickName:[dic objectForKey:@"nick"]];
    NSString * avatarString = [dic objectForKey:@"avatar"];
    NSRange rang = [avatarString rangeOfString:kYoupaiyunURL];
    avatarString = [avatarString substringFromIndex:rang.location + rang.length];
    NSString * urlString = [commonTool fangdaolianUPY:[NSString stringWithFormat:@"/%@",avatarString]];
    urlString = [NSString stringWithFormat:@"%@?_upt=%@",[dic objectForKey:@"avatar"],urlString];

    [cell setImageURLString:[NSString stringWithFormat:@"%@",urlString]];
    [cell _initViews];

    if (([self._tableViewData count]-1) == indexPath.row) {
        self.lastCommentTime = [[dic objectForKey:@"create_at"] intValue];


  }
    return cell;
}

应用程序崩溃。我确信这些方法没有问题,但我不知道是什么原因造成的。我需要一些有关可能导致此问题的指导。

【问题讨论】:

  • 控制台上打印的崩溃是什么?
  • 请发布更多崩溃日志详细信息,以便我们了解实际问题。
  • 你应该返回所有代表方法...提供你做了什么
  • 可以分享-tableView:cellForRowAtIndexPath:的实现吗?
  • 控制台打印:“libc++abi.dylib:terminate_handler 意外抛出异常”。

标签: ios objective-c uitableview


【解决方案1】:

可能的崩溃点是

[cell setTimeString:[self commentTimeTransfer:[dic objectForKey:@"create_at" ]]];

或在

if (([self._tableViewData count]-1) == indexPath.row) {
        self.lastCommentTime = [[dic objectForKey:@"create_at"] intValue];

只需检查数组,字典不会变空,或者如果您将此方法中的任何值传递给另一个,也请检查那里。希望您的问题能得到解决。

您可以进行调试,在哪一行出现崩溃。

请分享崩溃详情,否则无人能提供帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-22
    • 2016-02-11
    • 2018-10-25
    相关资源
    最近更新 更多