I have a button in my view controller and I want to connect my button to table view controller (It means that when I click on button it loads and brings my table)
bu
I think the button is in FirstViewController. If it is then implement -(IBAction)clickButton and write code and connect it to your bottom in Interface Builder(If you use Interface Builder) . write createViewController
object and #import
in FirstViewController.h
In FirstViewController.h,
#import "CreateViewController.h"
@interface FirstViewController : UIViewController{
CreateViewController *createViewController;
}
-(IBAction)clickButton:(id)sender;
@end
In FirstViewController.m, you just add below method
-(IBAction)clickButton:(id)sender{
if (!createViewController) {
createViewController = [[CreateViewController alloc] initWithNibName:@"CreateViewController" bundle:nil];
}
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backBarButtonItem;
[backBarButtonItem release];
[self.navigationController pushViewController:createViewController animated:YES];
}
and in AppDelegate.h,
#import "FirstViewController.h"
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) FirstViewController *viewController;
@property (nonatomic, retain) UINavigationController *navControl;
@end
In AppDelegate.m,
@synthesize window;
@synthesize viewController;
@synthesize navControl;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] autorelease];
navControl = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:[navControl view]];
[self.window makeKeyAndVisible];
return YES;
}