Я хочу, чтобы в главном окне отображалось созданное представление modalViewController при нажатии информационной кнопки.Но когда я нажимаю кнопку Info в главном окне, ничего не происходит.
В файле mainviewcontroller.h у меня есть следующий код:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface imageviewViewController : UIViewController{
AVAudioPlayer *audioPlayer;
}
@property (nonatomic, retain) UIToolbar *toolbar;
@property (nonatomic, assign) UIBarButtonSystemItem currentSystemItem;
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@end
В файле mainviewcontroller.m есть следующий код:
#import "imageviewViewController.h"
#import "Infoviewcontroller.h"
@implementation imageviewViewController
@synthesize toolbar;
@synthesize currentSystemItem;
@synthesize audioPlayer;
UIBarButtonItem *infoItem = [[UIBarButtonItem alloc]
initWithTitle:@"Info"
style:UIBarButtonItemStyleBordered
target:nil
action:@selector(Infobuttonpressed)];
// flex item used to put space in between buttons
UIBarButtonItem *flexItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil
action:nil];
//Add buttons to the array
NSArray *toolbarItems = [NSArray arrayWithObjects: settingsButton, flexItem, systemItem, flexItem, systemItem1,flexItem, systemItem2, flexItem, systemItem3, flexItem, infoItem, nil];
[toolbar setItems:toolbarItems];
[settingsButton release];
[systemItem release];
[systemItem1 release];
[systemItem2 release];
[systemItem3 release];
[infoItem release];
[flexItem release];
[super viewDidLoad];
}
- (void) Infobuttonpressed: (id) sender
{
Infoviewcontroller *myView = [[Infoviewcontroller alloc] init];
[self presentModalViewController:myView animated:YES]; // present view modally
[self.navigationController pushViewController:myView animated:YES]; // add to navigation stack
[myView release];
}
В файле Infoviewcontroller.h есть следующий код:
#import <UIKit/UIKit.h>
@interface Infoviewcontroller : UIViewController <UITextViewDelegate>
{
UITextView *textView;
}
@property (nonatomic, retain) UITextView *textView;
@property (nonatomic, assign) UINavigationBar *navBar;
@end
Тогда в файле infoviewcontroller.m есть следующий код:
#import "Infoviewcontroller.h"
@implementation Infoviewcontroller
@synthesize textView;
@synthesize navBar;
-(void)dealloc
{
[textView release];
[navBar release];
[super dealloc];
}
-(void)setupTextView
{
self.textView = [[[UITextView alloc] initWithFrame:self.view.frame] autorelease];
self.textView.textColor = [UIColor redColor];
self.textView.font = [UIFont fontWithName:@"System Bold" size:13];
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.textAlignment = UITextAlignmentCenter;
self.textView.text = @"This is UITextView\nThis is UITextView\nThis is UITextView\nThis is UITextView";
[self.view addSubview: self.textView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
navBar = [[UINavigationBar alloc] init];
UINavigationItem *navItem = [[[UINavigationItem alloc] initWithTitle:@"ModalViewControllerTest"] autorelease];
UIBarButtonItem *done = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissView:)] autorelease];
navItem.rightBarButtonItem = done;
navBar.items = [NSArray arrayWithObject:navItem];
[self.view addSubview:navBar];
}