Note that there are some explanatory texts on larger screens.

plurals
  1. POpushViewController in Xcode
    primarykey
    data
    text
    <p>I'm trying to push a view from a table cell to another view, I know that there's a lot of tutorials out there, I've tried a lot of them, been trying for 2 days and still can't get it working, here's my code..</p> <p>AppDelegate.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @class RootViewController; @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt; @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) RootViewController *rootViewController; @end </code></pre> <p>AppDelegate.m</p> <pre><code>#import "AppDelegate.h" #import "RootViewController.h" @implementation AppDelegate @synthesize window = _window; @synthesize rootViewController; - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.rootViewController = [[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil] autorelease]; self.window.rootViewController = self.rootViewController; [self.window makeKeyAndVisible]; return YES; } @end </code></pre> <p>RootViewController.h</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface RootViewController : UITableViewController{ NSMutableArray* array; } @property(nonatomic, retain)NSMutableArray* array; @end </code></pre> <p>RootViewController.m</p> <pre><code>#import "RootViewController.h" #import "SubLevelViewController.h" @implementation RootViewController @synthesize array; - (void)viewDidLoad { [super viewDidLoad]; array = [[NSMutableArray alloc] init]; [array addObject:@"One"]; [array addObject:@"Two"]; [array addObject:@"Three"]; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. self.navigationItem.rightBarButtonItem = self.editButtonItem; } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { // Release anything that can be recreated in viewDidLoad or on demand. // e.g. self.myOutlet = nil; } #pragma mark Table view methods - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } // Customize the number of rows in the table view. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [array count]; } // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } NSString *cellValue = [array objectAtIndex:indexPath.row]; cell.textLabel.text = cellValue; // Configure the cell. return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { SubLevelViewController *sub = [[SubLevelViewController alloc] initWithNibName:@"SubLevelViewController" bundle:nil]; sub.title = @"My First View"; [self.navigationController pushViewController:sub animated:YES]; } - (void)dealloc { [array release]; [super dealloc]; } @end </code></pre> <p>and main.m</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload