How to add row/cells dynamically to an UITableView by pressing a button in iPhone

iphone, objective-c, uitableview

Solution

In your application You have to add values to Array when you performing action in btn.

For example in your tableview you are displaying NSString in cell.textLABEL.text. These strings are in NSMutableArray.

Now when buttonAction is called

in myAction

{
    NSString *newString =@"NEW CELL";

    [tableArray addObject:newString];
    [tableView reloadData];
}

Try this logic in your application regarding to your modal.

I hope this logic will be helpful to you.

Problem

Initially i have a table view with only one add button. when user press this button i need to increment the cells count and add the cells as follows How to write row count and how to add new rows by click on the add button //Row count ``` - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return **????** ; } ``` // Content on cells/rows ``` - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { ?????? } ``` // ### Add New Row.. ### ``` -(IBAction)myAction:(id)sender { ???????? ; } ``` Thanks in advance...

Original source

Related problems