First ViewController.xib содержит 4 представления (без UINavigationController в xib).
- "ViewController.h" - здесь ...
- "GlavView.h" - полученоздесь ...
Как вернуться к 1 (ViewController.h)?
// Методы
- (IBAction) iBM_GlavView:(id)sender;
- (void) iDM_GlavView;
Эти методы недоступны в GlavViewЕсли я не привязал кнопку выбора к первому ответчику, но они доступны в ViewController.m
Если вы используете Interface Builder, то он работает, но я не хочу использовать Interface Builder, ибез него, чтобы связаться с ViewController, я не знаю.
Спасибо за любую помощь!
Вот часть кода приложения:
--------------- AppDelegate.h
//
// AppDelegate.h
//
//
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : NSObject <UIApplicationDelegate> //UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;
@end
--------------- ViewController.h
//
// ViewController.h
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
UINavigationController *navigationController;
}
@property (retain, nonatomic) IBOutlet UINavigationController *navigationController;
- (IBAction) iBM_GlavView:(id)sender;
- (void) iDM_GlavView;
@end
--------------- ViewController.m
//
// ViewController.m
// SeifNote
//
// Created by Saveliy Severniy on 19.01.12.
// Copyright (c) 2012 Saveliy Severniy. All rights reserved.
//
#import "ViewController.h"
#import "GlavView.h"
@implementation ViewController
@synthesize navigationController;
- (void)viewDidLoad
{
[super viewDidLoad];
if( isLogin )
{
// Ok
[self iDM_GlavView];
}
else
{
[self.view addSubview:self.viewEnterPass];
}
}
- (IBAction)iBM_GlavView:(id)sender{
if (self.navigationController == nil) {
//navigationController is declared as: UINavigationController * navigationController;
navigationController = [[UINavigationController alloc] init];
GlavView *myOptions = [[GlavView alloc] initWithNibName:@"GlavView" bundle:nil];
[navigationController pushViewController:myOptions animated:NO];
[myOptions release];
}
[self.view addSubview:navigationController.view]; // From this point begins the work UINavigationController in a new view
}
- (void) iDM_GlavView {
if (self.navigationController == nil) {
// navigationController is declared as: UINavigationController *optionsRootController;
navigationController = [[UINavigationController alloc] init];
GlavView *myOptions = [[GlavView alloc] initWithNibName:@"GlavView" bundle:nil];
[navigationController pushViewController:myOptions animated:NO];
[myOptions release];
}
[self.view addSubview:navigationController.view];
}
--------------- GlavView.ч
//
// GlavView.h
//
#import <UIKit/UIKit.h>
@interface GlavView : UITableViewController {
UIToolbar *toolbar;
IBOutlet UIBarButtonItem *addButtonItem;
}
@property (nonatomic, retain) UIBarButtonItem* addButtonItem;
@end
--------------- GlavView.m
//
// GlavView.m
//
#import "GlavView.h"
@implementation GlavView
@synthesize addButtonItem;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// is declared as: UIBarButtonItem *addButtonItem;
self.navigationItem.rightBarButtonItem = self.addButtonItem;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
//Initialize the toolbar
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
//Set the toolbar to fit the width of the app.
[toolbar sizeToFit];
//Caclulate the height of the toolbar
CGFloat toolbarHeight = [toolbar frame].size.height;
//Get the bounds of the parent view
CGRect rootViewBounds = self.parentViewController.view.bounds;
//Get the height of the parent view.
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);
//Get the width of the parent view,
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);
//Create a rectangle for the toolbar
CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);
//Reposition and resize the receiver
[toolbar setFrame:rectArea];
//Create a button
UIBarButtonItem *testButton = [[UIBarButtonItem alloc]
initWithTitle:@"Del" style:UIBarButtonItemStyleBordered target:self action:@selector(test_clicked:)];
[toolbar setItems:[NSArray arrayWithObjects:testButton,nil]];
[testButton release];
//Add the toolbar as a subview to the navigation controller.
[self.navigationController.view addSubview:toolbar];
//Reload the table view
[self.tableView reloadData];
}
- (void) test_clicked:(id)sender {
// iBM_GlavView is declared in ViewController.h
[??? iBM_GlavView]; // How to get out of here (GlavView) and return (ViewController)?
}