0

I'm at the final stage of my first iPhone app and I can't for the life of me get this to work. I have a Table View and I want to have an "Add" button that goes to another controller (modal, I think) where the user can enter a string and click "Done". This should bring the user back to the Table View, which is updated to include the newest row on the bottom. (Data for rows is being stored in an array in NSUserDefaults.)

I'm following this guide: https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW1

I got the Add button to appear. But I don't understand the next part.

- (void)addItem:sender {
if (itemInputController == nil) {
    itemInputController = [[ItemInputController alloc] init];
}
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:itemInputController];
[[self navigationController] presentModalViewController:navigationController animated:YES];
}

What is ItemInputController and is this something I need to define myself? The documentation doesn't say how. It also doesn't say how to design the text input view. I'm guessing this is all done programatically, but then how do you set up the segue between the Add button and this new modal view.

What I've tried so far (also using other tutorials online and SO answers) has failed so far. Any help would be much appreciated!

2
  • itemInputController is the root view controller. You may define your own root view controller. Mar 4, 2015 at 0:16
  • I ended up using UIAlertView for data input and connected it to the Add button. Works better for my app, and easier to implement since I don't have to pass around values between controllers and set up segues.
    – Jey
    Mar 4, 2015 at 1:33

1 Answer 1

1

ItemInputController is some custom class in some example app in its code. It is probably a subclass of UIViewController. It contains something useful to the user..some UI or some textfields..we can't know.

Anyway, that input controller is then wrapped in UINavigationController which is purely give it a nice navigation bar at the top that can hold buttons. This step is not mandatory..it is only for design considerations (to have that bar really and to be able to put cancel and add buttons into that bar.)

What you need to do is

1) create your own SomethingViewController

2) put whatever you want to put there, including the Cancel and Add navigation bar buttons

3) then present it the same way as it is done in the code example.

Basicaly your custom view controller will serve as a platform mto add some data. When the user will press Add, you should keep that data in your model layer, and then when you return to table view, you would reload data for table view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.