2011年6月20日 星期一

Navigation 使用心得

構想: two view
1. main view: include current time and battery status
2. table view: record current time and battery level, using NSTimer

main view按下info button會顯示table view

----------------------------------------------------------------------------------------
xcode:
new project -> view-based application (name: PowerBank)

//PowerBankAppDelegate.h

#import <UIKit/UIKit.h>
@class PowerBankViewController;
@interface PowerBankAppDelegate : NSObject <UIApplicationDelegate> {
     UIWindow *window;
UINavigationController *navigationController;
  PowerBankViewController *viewController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet PowerBankViewController *viewController;
@end




//  PowerBankAppDelegate.m
#import "PowerBankAppDelegate.h"
#import "PowerBankViewController.h"




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

navigationController = [[UINavigationController alloc] init];
PowerBankViewController *_powerBankViewController = [[PowerBankViewController alloc] init];
_powerBankViewController.title = @"Battery State";
[navigationController pushViewController:_powerBankViewController animated:NO];
[_powerBankViewController release];
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}


 建立IBAction in main view , 目的為秀table view

-(IBAction)showDataTble:(id)sender
{
DetailData *_showDetailData = [[DetailData alloc] init];
_showDetailData.receiveArrayBatLevel = arrayBatLevel;
_showDetailData.receiveArrayCurTime = arrayCurTime;
[self.navigationController pushViewController:_showDetailData animated:YES];
[_showDetailData release];
}

沒有留言:

張貼留言