Post

Replies

Boosts

Views

Activity

How to create navigationController programmatically
Hi developers, I created a new project like this : iOS / App / Storyboard / Objective-C. Added an UITableView inside the default named ViewController class. Objective-C is 100% compatible with C, it's great! When I click on a table cell, I wanted to navigate to another view of View2 class. But the navigationController is nil inside the tableView:didSelectRowAtIndexPath: method. I had to do it through the Xcode UI: " Editor / Embed in / Navigation Controller ", this worked. But my question is: How can I create navigationController programmatically? I don't want to do it with Storyboard because sometimes I delete some UI elements some files still keep the deleted elements. I read some posts and some said, create instance of "ViewController" in AppDelegate.m in application: didFinishLaunchingWithOptions . Isn't the default name "ViewController" created automatically by the procedure? How can I interrupt this procedure? Thanks! - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { View2 *view = [[View2 alloc] init]; view.text = self.mutArray[indexPath.row]; // navigationController is nil [self.navigationController pushViewController:view animated:YES]; } Xcode: Version 13.1 (13A1030d), macOS: 12.0.1 (21A559)
2
0
2.9k
Nov ’21
How to create navigationController programmatically
Hi developers, I created a new project like this : iOS / App / Storyboard / Objective-C. Added an UITableView inside the default named ViewController class. Objective-C is 100% compatible with C, it's great! When I click on a table cell, I wanted to navigate to another view of View2 class. But the navigationController is nil inside the tableView:didSelectRowAtIndexPath: method. I had to do it through the Xcode UI: " Editor / Embed in / Navigation Controller ", this worked. But my question is: How can I create navigationController programmatically? I don't want to do it with Storyboard because sometimes I delete some UI elements some files still keep the deleted elements. I read some posts and some said, create instance of "ViewController" in AppDelegate.m in application: didFinishLaunchingWithOptions . Isn't the default name "ViewController" created automatically by the procedure? How can I interrupt this procedure? Thanks! - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { View2 *view = [[View2 alloc] init]; view.text = self.mutArray[indexPath.row]; // navigationController is nil [self.navigationController pushViewController:view animated:YES]; } Xcode: Version 13.1 (13A1030d), macOS: 12.0.1 (21A559)
Replies
2
Boosts
0
Views
2.9k
Activity
Nov ’21