2016-03-17 43 views
1

我已經用UITableView.UITableView創建了一個iOS應用,默認加載了25條記錄。我正在滾動tableview來獲得另外25條記錄。如何使超過25條記錄的UITableView滾動顯示?

如何獲得另一組數據?

這是我的代碼。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return timeList.count; 
} 

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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell=[[UITableViewCell alloc]initWithStyle: 
       UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 
    } 
    NSDictionary *tmpDict = [timeList objectAtIndex:indexPath.row]; 
    NSMutableString *text; 
    NSString *currentstatus; 
    text = [NSMutableString stringWithFormat:@"%@",[tmpDict objectForKeyedSubscript:startdate]]; 
    currentstatus = [self statusString:[NSMutableString stringWithFormat:@"%@",[tmpDict objectForKeyedSubscript:status]]]; 
    NSMutableString *detail; 
    detail = [NSMutableString stringWithFormat:@"User:%@ , Hours:%@ , Status: %@ ", 
       [tmpDict objectForKey:username], [tmpDict objectForKey:hours], currentstatus]; 
    cell.textLabel.text = text; 
    cell.detailTextLabel.text= detail; 
    cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator; 
    return cell; 
} 
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    NSDictionary *tmpDict = [timeList objectAtIndex:indexPath.row]; 
    NSString * [email protected]"Main"; 
    UIStoryboard *storyboard =[UIStoryboard storyboardWithName:storyboardName bundle:nil]; 
    EditViewController *evc =[storyboard instantiateViewControllerWithIdentifier:@"EditViewController"]; 
     evc.startday =[NSMutableString stringWithFormat:@"%@",[tmpDict objectForKeyedSubscript:startdate]]; 
    evc.user_id = [NSMutableString stringWithFormat:@"%@",[tmpDict objectForKeyedSubscript:user_id]]; 
    evc.tab [email protected]"wktime"; 
    [self presentViewController:evc animated:NO completion:Nil]; 
} 

回答

1

可以使用的UIScrollView scrollViewDidEndScrolling的委託方法加載更多的數據,然後你可以刷新你的tableView。

4

首先檢查tableview是否到達最後一個單元格。如果達到了,那麼你必須重新加載下一組數據。

使用下面的代碼來檢查tableview是否到達最後一個單元格。

-(void)tableView:(UITableView *)tableView willDisplayCell (UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == timeList.count-1) 
    { 
     //Your code here 
    } 
} 
1

你可以用簡單的方法做到這一點。通過在cellForRowAtIndexPath委託方法中添加以下代碼。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.row == timeList.count-1) { 
    NSLog(@"load more"); 
    } 
    ..... 
    return cell; 
} 

如果條件將在tableview結束時執行,那麼您可以添加您的邏輯來加載更多數據。