Q:

UITableView add more cells with Click

I added UIButton in the last cell of UITableView, and I want to show more cells with click..
- (void)viewDidLoad {
    [super viewDidLoad];

    rowCount = 15;
    dataArray = [[NSMutableArray alloc] init];
    for (int i = 0; i < 100; i++) {
        NSString *value = [NSString stringWithFormat:@"the value of row is: %d", i +1];
        [dataArray addObject:value];
    }

}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *idintify = @"Cell";
    UITableViewCell *cell = [self.myTable dequeueReusableCellWithIdentifier:idintify];

    [cell.textLabel setText:dataArray[indexPath.row]];

    if (indexPath.row == rowCount -1) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.myTable.frame.size.width, 44)];
        [button addTarget:self action:@selector(cellButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        [button setBackgroundColor:[UIColor yellowColor]];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitle:@"Show more..." forState:UIControlStateNormal];
        [cell addSubview:button];

    }

    return cell;
}

...
- (void)cellButtonClicked
{
    if (rowCount +10 >= dataArray.count) {
        rowCount = dataArray.count;

    } else {
        rowCount += 10;
    }
    [self.myTable reloadData];
    NSLog(@"%ld", (long)rowCount);
}

At beginning its work properly, But when I scrolled the table the cell did not changed!

I want to show the button at last cell

A:

Cells in a table view are reused when the user scrolls. When you add a button to an instance of your cell prototype and don't remove it, the button remains, even if the cell is used at another index later. This results in what you have on your screenshots. 
You should create two cell prototypes in the interface builder and your cellForRow:atIndexPath: should look something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return cell with data

    if (indexPath.row < dataArray.count) {
        UITableViewCell *cell = [self.myTable dequeueReusableCellWithIdentifier:@"cell_prototype_1"];
        [cell.textLabel setText:dataArray[indexPath.row]];
        return cell;
    }     

    // If it's the last index, return cell with button

    else {
        UITableViewCell *cell = [self.myTable dequeueReusableCellWithIdentifier:@"cell_prototype_2"];
        return cell;
    }

    // This won't get called

    return [UITableViewCell new];
}

