2017-01-10 16 views
0

我是iOS新手,面臨着自動滾動表格視圖單元格的問題。 我使用這樣的代碼如何自動滾動目標中的自定義表格視圖單元格C

- (void)viewDidAppear:(BOOL)animated{ 

    [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height) 
       animated:YES]; 

    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[headarray count]-1 inSection:0]             
        atScrollPosition:UITableViewScrollPositionBottom 
          animated:YES]; 
} 

但它讓我壞訪問什麼,我提前做錯了這個code.Thanks!

我試試你這樣的代碼在connectionDidFinishLoading方法

if ([headarray count] != 0) { 

      NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[headarray count]-1 inSection:0]; 
      [Newstable scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO]; 
     } 
+0

你的代碼是完全正確的,但檢查了這'[musicGenre數] -1切入口:0]',它是什麼返回,檢查它的價值和等級。 –

+0

@muja嘗試我的代碼,只是刪除你的[表setContentOffset:CGPointMake(0.0,table.contentSize.height - table.bounds.size.height) animated:YES];這條線 –

+0

@Muju你想在最後一排桌子上滾動嗎? –

回答

2

退房此鏈接https://github.com/danielamitay/DAAutoScroll。你可以使用這些類來自動滾動你的tableview。 1.導入類

進口 「DAAutoScroll.h」

- (void)viewDidLoad { 
    [self performSelector:@selector(scrollDown) withObject:self afterDelay:3.0]; 
} 

-(void)scrollDown{ 

    yourtableview.scrollPointsPerSecond = 20.0f; 
    [yourtableview startScrolling]; 

} 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate 
{ 
    if (!decelerate) { 
     [yourtableview startScrolling]; 
    } 
} 

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView 
{ 
    [yourtableview startScrolling]; 
} 
+0

在演示中它工作的很完美,但是當我在項目中使用它時,它不起作用。 – Muju

+0

@Muju當你嘗試在項目中使用它時,會出現什麼問題? –

+0

@PiyushPatel自動滾動不起作用。 – Muju

0
[tableviewname setContentOffset:CGPointMake(0, ([arrayofcontact count]-10)*cellheight) animated:YES]; 
+2

這段代碼做了什麼,它爲什麼解決這個問題? – JJJ

相關問題