2016-07-26 1 views
0

私はtableviewを持っています。それはサーバーからのデータの混乱を受信します。テーブルビューのデータを受け取るたびに最新のものを表示したいのですが、scrollToRowAtIndexPath:atScrollPosition:animated:と呼ばれますが、スクロールしても画面内で何もできません。 はここに私のメインのコードUITableView scrollToRowAtIndexPath:atScrollPosition:アニメーション:真剣に私のアプリを遅らせる

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *identifier = @"tableViewCell"; 

    DLtestCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 
    } 
    NSDictionary* dict = arr[indexPath.row]; 
    cell.myLabel.attributedText = dict[@"content"]; 
    [cell.myImageview sd_setImageWithURL:dict[@"imageUrl"] placeholderImage:[UIImage imageNamed:@"transparentPlaceHolder"]];  
    return cell; 
} 

、ここではあなたがscrollToRowAtIndexPathメソッドを使用する必要があります

- (void)reloadTableView 
{ 
    dispatch_async(dispatch_get_main_queue(), ^{ 

     NSIndexPath *lastRow = [NSIndexPath indexPathForRow:row inSection:0]; 
     [self.tableView insertRowsAtIndexPaths:@[lastRow] withRowAnimation:UITableViewRowAnimationLeft]; 
    }); 
     [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO]; 
} 
+0

メインスレッド(performOnMainThread)のメソッド – SM18

答えて

0

下メインコードにスクロールされます。

そして、viewWillAppearでは以下のコードを書いています。ここ

[theTableView reloadData];  
NSIndexPath* ip = [NSIndexPath indexPathForRow:rowNumber inSection:sectionNumberHere]; 
[theTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:NO]; 

「ROWNUMBERは、」あなたがにスクロールするデータソース内の行番号です。

または次のように 'ROWNUMBER' を計算することができます。

int lastRowNumber = [tableView numberOfRowsInSection:0] - 1; 

とindexPathForRowこのlastRowNumberを渡します。

注:numberOfRowsInSectionは、最後の行番号(行数-1)ではなく、行数を返します。

+0

に実際にリロードしようとしましたが、実際にはこのようにしていますが、データアクセスの混乱が原因で何も操作できません –

関連する問題