0

Say I have an iPhone app using a tableview. As shown below, if I click the edit button I go into edit mode. Then I have the option to delete or add. So far so good, and all of my code is working. However, what about modifying one the the cells?

The first cell, for example, is Chevy. Say I want to change it to Ford. How can I edit a cell's value while in edit mode?

Is there another button I can add called "Change"? If so what would the code be for this?

Having looked around Google I can't find any results for this type of question. Does anyone know any good tutorials? Or at the very least, can someone provide some ideas and perhaps code samples to get started?

Screen Shot 2013-02-12 at 3.02.51 PM

4

1 回答 1

1

Depends how you want the user experience to be. One option would be to use the TableView delegate method didSelectRowAtIndexPath to take the user to another page with a text field and a save button.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UIViewController* myEditCarDetailsViewController = [[UIViewController alloc] init]

[self.navigationController pushViewController:myEditCarDetailsViewController animated:YES];
}

Once the user clicked save, you just need to update the datasource and call reloadData on the tableView.

Another option would be to make a custom tableView cell that has a textField in it that you set to editable when the table is in edit mode.

I'm guessing you were hoping for an in built apple way. I don't know of one, but it may exist

于 2013-02-12T23:30:02.803 回答