UItableView, удалить и добавить строки в начале / конце Upradates - PullRequest
1 голос
/ 22 сентября 2011

Привет, у меня есть какой-то кусок кода с таблицей и некоторыми элементами в нем.

Я бы хотел, чтобы вы посоветовали мне, как удалить и добавить несколько строк с анимацией.

Когда пользователь прокручивает вниз до последней строки, код «показать следующие 5 элементов» должен обнаружить его, и последняя строка была удалена, и будет показан следующий 5 элемент.

как определить, что таблица прокручиваласьк низу.

#import "tableAddRemoveViewController.h"

@implementation tableAddRemoveViewController

@synthesize myTable, listOfItems;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    next5item = [[NSArray alloc] initWithObjects:@"next Item1", @"next Item2", @"next Item3", @"next Item4", @"next Item5", nil];

    [self showItems];
    [super viewDidLoad];
}



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

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];

    return cell;
}

-(void) showItems
{
    NSLog(@"Button Pressed");

    listOfItems = [[NSMutableArray alloc] initWithObjects:@"item1", @"item2", @"item3", @"item4", @"item5", @"item6", @"item7", @"item8", @"item9", @"item10", @"item11", @"item12", @"item13", @"item14", @"item15",@"show next 5 items", nil];

    NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];

    for (NSInteger i = 0; i < [listOfItems count]; i++) {
        [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:0]];
    }   

    [myTable beginUpdates];
    [myTable insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationLeft];
    [myTable endUpdates];
}

-(void) removeLastRow
{
    NSLog(@"removeLastRow");
}

@end

thx

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...