HI i have some piece of code with table and some items in it.
i'd like to u advise me, how to remove and add some rows with animation.
When user scroll down to the last row "show next 5 item" code should to detect it and last row was removed and next 5 item will showed.
how to detect that table was scrolled to the bottom.
#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
精彩评论