1

I am new to Xcode and am having trouble with my single view/view-based application for iPhone.

I have 2 buttons on the view and I need simple beginner instructions on how to make 1 button go to a different page and have a back button and have the other button on that view do the same as the first button.

Can anyone help? Thanks!

yuji
  • 16,695
  • 4
  • 63
  • 64
user1186514
  • 49
  • 2
  • 3
  • 6

2 Answers2

2

You are likely looking for a UINavigationController. There are many good tutorials for getting started with that.

This has links to some sample code: https://developer.apple.com/library/IOs/#documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html

picciano
  • 22,341
  • 9
  • 69
  • 82
  • It looks like the link is now dead, but I think [this article](https://developer.apple.com/documentation/uikit/uinavigationcontroller?language=objc) covers the same thing, though unfortunately it does not seem to have much in the way of sample code. – jrh Jan 03 '21 at 19:05
0

You need navigation based app. Take a look at here: https://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/TableView_iPhone/TableViewAndDataModel/TableViewAndDataModel.html to understand what a navigation based app and how that works with uitableview.

Raymond Wang
  • 1,484
  • 2
  • 18
  • 33
  • Sadly, they took the navigation-based application template out of the latest versions of Xcode. – picciano Feb 09 '12 at 22:32
  • Yea, that's pretty sad. Luckily it is not too complicated to do it from the scratch. Plus it would be easy to download a navigation based app and modify it. I agree with you, and I think it is a stupid idea to take that template away. But you know Apple, they always do what they want... – Raymond Wang Feb 09 '12 at 22:46
  • But how do I connect the UINavigationController to my buttons which later leads to pages with both UINavigationController and UITableView? – user1186514 Feb 13 '12 at 21:15
  • The easiest way would be using - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath and do [self.navigationController pushViewController:detailViewController animated:YES]; And that's the pretty standard way of doing it. I know you wanna put buttons but you can use the cell itself as a button. – Raymond Wang Feb 14 '12 at 19:29
  • And if you do want to make the buttons looks like not in a UITableView, there are probably different ways of doing it. Here is the way I done before: Make a UITableView to contain only one section and one row, then it will looks like a button and you could handle your navigation job in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. – Raymond Wang Feb 14 '12 at 19:36
  • It looks like the link in this post is now dead, I'm having trouble finding an exact replacement, but [Replacement for Navigation-based application template in Xcode 4.2?](https://stackoverflow.com/q/8196123/4975230) and maybe [Table Views](https://developer.apple.com/documentation/uikit/views_and_controls/table_views?language=objc) are relevant? – jrh Jan 03 '21 at 19:08