Okay, first off I think what you are doing with [self.view addSubview]
is piling all the views in your project into the same view controller, where the more traditional way to do it is to dismiss a view controller when you are done with it and create the new view controller on it's own. The piling up you are doing is unconventional, and I think it will be misleading to whoever tries to look at your code in the future. Additionally, it's going to be a headache if you actually start trying to do standard navigation. Also, it looks like a memory management nightmare (although I admit I'm still a little fuzzy on that, so I don't know if ARC would clean it up for you or not, if you are actually using ARC). That said, there are cases where you might be trying to do that - but if you're not sure, that means it isn't what you want to be doing (if it is what you want to do, check out XJones' answer). What I think you're looking for is presentViewController
- that is the more conventional way to get rid of an unneeded controller and replace it with a new one. Get rid of
vc2.view.frame = {...}
[self.view addSubview: vc2.view]
and replace it with
[self presentViewController:vc2 animated: completion:NULL];
NOTE: I'm not entirely sure what completion
does (I think it maybe allows you to run an extra method once vc2 is built - there are some examples if you google "presentViewController examples" that you could take a look at to get more information, or check the Apple Docs). I do know that keeping it NULL
will work, and probably do what you need.
Once you do all this, you will be right back to where you are now, where you will have a view with a bunch of empty cells on it (but you will have gotten there in a more conventional way).
From here, you need to add some code to your SecondViewController.m to tell it what you want to show. Generally, you'll have an array of strings and you want the 1st cell of your table to have a label that displays 1st string in that array, 2nd cell shows 2nd string, and so on. To do this, you'll have something like cell.textLabel = [myArray objectAtIndex:indexPath.row];
.
There is a lot more to setting up a UITableViewController than I could get into in this post, so check out some tutorials on YouTube or something, as they have already taken the time to explain everything you need in a much more digestible format (I found this one to be very helpful when I was first starting using table views, but there are tons of others there too).
UITableViewController
or how to set the cell's content for theUITableView
? - Steven