0
votes

I would like to add a new table cell each time my button is pressed. The cell is being populated with data the user has entered into the text fields in a previous view controller, and passed to the table view controller. Right now, when the button on the view controller is pressed, the data overrides whatever information was previously in that cell. I want to add a brand new cell while still keeping the previous cells. I know I need to add to my arrays, but I am not sure where to add the code to add a new cell. Do I add it in the View Controller "prepare for segue" portion? Or do I add it somewhere in my Table View Controller? Here is my prepare for segue and my arrays... Thank you for any help, I am really stuck on this one.

-In my view controller:

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

if ([segue.identifier isEqualToString:@"goToMatch"])
{
    MatchesViewController *destinationVC = segue.destinationViewController;
    Connector *connectorClass = [[Connector alloc]init];
    connectorClass.stringBeingPassedDetails = _detailsField.text;
    connectorClass.stringBeingPassedAddress = _parkField.text;
    connectorClass.stringBeingPassedCity = _cityField.text;
    connectorClass.stringBeingPassedSport = _TitleLabel.text;
    connectorClass.stringBeingPassedDate = _label.text;
    connectorClass.stringBeingPassedPeople = _peopleField.text;
    destinationVC.connectorClass = connectorClass;

}

In view did load of my table view controller:

 _detailsTitle = @[connectorClass.stringBeingPassedDetails];

_addressTitle = @[connectorClass.stringBeingPassedAddress];

_cityTitle = @[connectorClass.stringBeingPassedCity];

_sportTitle = @[connectorClass.stringBeingPassedSport];

_dateTitle = @[connectorClass.stringBeingPassedDate];

_peopleTitle = @[connectorClass.stringBeingPassedPeople];

Each array populates a corresponding label in the cell.

1

1 Answers

0
votes

You should implement the UITableViewDelegate:

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

and UITableViewDataSource:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"yourCustomIdentifier"];
    //set your cell
    return cell;
}