在UITableView

时间:2018-03-22 05:25:34

标签: ios objective-c uitableview

问题:在滚动表格时再次调用API 我所做的代码:

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    ITableViewCell* cell = ( ITableViewCell* )[self.tblNotes dequeueReusableCellWithIdentifier:@"NoteTableCell"];

    cell.tag = indexPath.row;
    if(cell.tag == indexPath.row) {
        cell = [cell initWithNote:[notesArray objectAtIndex:indexPath.row]];
    }
    [cell setNeedsLayout];
    [cell setNeedsDisplay];
    return cell;
}  

我不想在滚动时调用initWithNote

先谢谢。

2 个答案:

答案 0 :(得分:1)

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

   ITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"NoteTableCell"];
    if (cell == nil) {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"NoteTableCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }

    id object = [notesArray objectAtIndex:indexPath.row];
    if ([object isKindOfClass:[NSDictionary class]]) {
        NSDictionary *dict = (NSDictionary *)object;
        [cell.userNameforNotes setText:[NSString stringWithFormat:@"%@",[[dict valueForKey:@"uploadedBy"] uppercaseString]]];
        [cell.noteDescription setText:[NSString stringWithFormat:@"%@",[[dict valueForKey:@"description"] uppercaseString]]];
        [cell.dateForNotes setText:[NSString stringWithFormat:@"%@",[[dict valueForKey:@"uploadedDate"] uppercaseString]]];
        NSString *urlString = [NSString stringWithFormat:@"%@", [dict valueForKey:@"incidentID"]];
        [cell.noteImage sd_setImageWithURL:[NSURL URLWithString:urlString]];
    }
    return cell;
}

答案 1 :(得分:0)

为此你可以检测tableview是否在这个委托scrollViewWillBeginDragging的帮助下滚动,如果是,那么你可以保留一些标志或某些东西,告诉你的代码不要调用initWithNote:。滚动完成后,您可以使用scrollViewDidEndDragging:进行检查,您可以执行任何操作。由于tableview包含scrollview,因此您可以轻松地从scrollview委托中获取帮助。

相关问题