tags:

views:

41

answers:

2

Finally managed to start fiddling with Xcode and Objective-C since yesterday. What I have now is

  1. A UIViewController which has in it

    • a UITextView
    • a Tab bar with a view Tab buttons (not functional yet)
    • a TableView
  2. I have coded basic functionality where a keyboard pops up on the TextView, and when you enter text and hit 'done', I am able to capture the text (using IBOutlet, IBAction etc.) in a method which shows an alert with the text entered. Essentially I can now capture the entered text within my code.

  3. What I want to do now is to enter this text as a row in the TableView - and I'm sort of lost now amidst controllers and views.

Where does the TableViewController fit into all this? I already have a TableView within this view controller, so how do I interact with it? Should I "somehow" be passing control to a separate TableViewController which I should create and add to my project? Or should I add a TableViewController to this UIViewController? I'm a bit confused.

Any pointers appreciated. You don't need to get into a lot of detail even - just a list of bullets that even say 'do this/do that' will help me go chasing the concepts. Right now I don't know which way to turn.

Thanks a bunch!

+1  A: 

Check out the UITableViewDataSource protocol. In particular you will need to implement the numberOfRowsInSection and cellForRowAtIndexPath methods.

You will pass your text into the cell's textlabel -- check out the UITableViewCell class for more info on that.

William Jockusch
hi William,My problem has more to do with how a TableViewController fits into a ViewController that I already have - my main view shows up but doesn't show the TableView which is in a different .nib file with its own TableViewController. I'm sort of knotted on how I can have a single window with all these UI elements with their own controllers.
John
A couple of options:[viewController.view addSubView: tableViewController.view];or[viewController.navigationController pushViewController: tableViewController animated: YES];
William Jockusch
A: 

If you are trying to add the uitableview to your view controller that includes the entry box, I would create the IBOutlet for the uitableview, add the tableview to your NIB and attach the delegate to file owner and attach the table to the IBOutlet. Then you will need to add an NSMutableArray (property, synthesize, and release) to your view controller which will be used when an item is added from the text box. Lastly each time an item is added to the text box, you call [myTable reloadData]; to refresh the tableview now that something else has been added.

As William mentioned in a seperate answer, you will to implement all of the required delegate methods for the UITableView (numberOfRowsInSection and cellForRowAtIndexPath) which will all work off of your array you are building.

There are more things to take into account such as should this data persist after the app closes but this should give you a start. Hope this helps!!

stitz
Thanks Stitz. I have managed to get past the hurdle from William's hints.
John