2010/08/05

[objective-c][iPad]Popoverを表示する

今日は、引き続き、iPadネタで、Popoverを出力する方法について
//sqliteBrowserAppDelegate.h

#import <UIKit/UIKit.h>
#import "MainNavigationController.h"
#import "MainViewController.h"

@interface sqliteBrowserAppDelegate : NSObject {
UIWindow *window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

//"sqliteBrowserAppDelegate.m
#import "sqliteBrowserAppDelegate.h"

@implementation sqliteBrowserAppDelegate

@synthesize window;


#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

MainViewController *mainviewcontroller = [[MainViewController alloc] initWithNibName:nil bundle:nil];
MainNavigationController *mainnavigationcontroller = [[MainNavigationController alloc]
initWithRootViewController:mainviewcontroller
];

[window addSubview:mainnavigationcontroller.view];
[window makeKeyAndVisible];

return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
}


- (void)applicationWillTerminate:(UIApplication *)application {
}


#pragma mark -
#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
}


- (void)dealloc {
[window release];
[super dealloc];
}

@end

//MainNavigationController.h
#import <UIKit/UIKit.h>
#import "MainViewController.h"

@interface MainNavigationController : UINavigationController {

}

@end

//MainNavigationController.m
#import "MainNavigationController.h"


@implementation MainNavigationController

- (id)initWithRootViewController:(UIViewController *)rootViewController{
if ((self = [super initWithRootViewController:rootViewController])) {

}
return self;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}


- (void)viewDidUnload {
[super viewDidUnload];
}


- (void)dealloc {
[super dealloc];
}


@end

//MainViewController.h
#import <UIKit/UIKit.h>
#import "MainPopoverController.h"

@interface MainViewController : UIViewController {

}

-(void)openPopover:(id)sender;
@end

//MainViewController.m
#import "MainViewController.h"

@implementation MainViewController

-(void)openPopover:(id)sender{
MainPopoverController *mainpopovercontroller = [[MainPopoverController alloc]
initWithContentViewController:[[UIViewController alloc] initWithNibName:nil bundle:nil]
];
[mainpopovercontroller presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {

UIBarButtonItem *menubutton = [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarButtonItemStyleBordered target:self action:@selector(openPopover:)];
menubutton.width = (CGFloat)150;
self.navigationItem.leftBarButtonItem = menubutton;

}

return self;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}


- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}


- (void)viewDidUnload {
[super viewDidUnload];
}


- (void)dealloc {
[super dealloc];
}


@end

//MainPopoverController.h
#import <UIKit/UIKit.h>


@interface MainPopoverController : UIPopoverController {

}

@end

//MainPopoverController.m
#import "MainPopoverController.h"


@implementation MainPopoverController


- (void)dealloc {
[super dealloc];
}


@end

実行結果はこちら↓
Photobucket
この機能っておそらくiPadだけの機能なんじゃーないのかなー。

Popoverが今は黒いけど、どんどんカスタマイズしていきたいなと。

0 コメント:

コメントを投稿