티스토리 뷰
IBAction을 사용하여 버튼 터치를 통해 View간의 전환을 위한 소스입니다.
AppDelegate.h 소스
─────────
#import <UIKit/UIKit.h>
@interface ChangeViewAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UIView *firstView;
IBOutlet UIView *secondView;
}
-(IBAction) ChangeView;
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
AppDelegate.m 소스
─────────
#import "ChangeViewAppDelegate.h"
@implementation ChangeViewAppDelegate
@synthesize window;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//어플리케이션이 런칭되고나서 실행되는 메소드
[window addSubview:firstView];
[self.window makeKeyAndVisible];
return YES;
}
- (IBAction) ChangeView
{
//UIwindow에 붙일 수 있는 View는 하나이므로 처음에 UIwindow에 View1을 넣었다가 다른 뷰로 보여주기 위해서 View1을 없애고 View2를 보여주는 방식으로 구현해야함
NSArray *subs = [window subviews];
//윈도우에서 subview 제거
[[subs objectAtIndex:0] removeFromSuperview];
//objectAtIndex가 secondView일 경우에는
if([subs objectAtIndex:0] == secondView)
{
//window에 firstView를 보여줌
[window addSubview:firstView];
}
else
{
//secondView가 아닐경우 secondView를 보여줌
[window addSubview:secondView];
}
}
- (void)applicationWillResignActive:(UIApplication *)application {
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
*/
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
/*
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}
- (void)applicationWillTerminate:(UIApplication *)application {
/*
Called when the application is about to terminate.
See also applicationDidEnterBackground:.
*/
}
#pragma mark -
#pragma mark Memory management
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
/*
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
*/
}
- (void)dealloc {
[window release];
[super dealloc];
}
@end
인터페이스 빌더에서는 mainwindow.xib을 열어 view를 두개 만들고 App Delegate와 연결한후
각 뷰에 버튼을 하나씩 넣고 버튼을 다시 App Delegate의 Received Actions에 연결해주면 됩니다.
다른 버전은 모르겠는데 Xcode 3.2에서
- (IBAction) ChangeView
{
}
Received Actions 항목이 안뜨니 참고하세요.
'헉!! > iOS' 카테고리의 다른 글
[iOS 개발] pickerView:numberOfRowsInComponent (0) | 2011.09.14 |
---|---|
[iOS 개발] TableView를 사용할 경우 행이 선택되었는지 확인해주는 메소드 (1) | 2011.08.04 |
[iOS 개발] 테이블 생성 및 글자 넣어 출력해보기 (0) | 2011.07.21 |
[iOS 개발] Xcode의 기본적인 화면구성 (2) | 2011.07.21 |
[iOS 개발] 아이폰 화면에 Hello World를 찍다 (0) | 2011.07.20 |
- Total
- Today
- Yesterday
- Objective-C
- iOS 개발
- iPhone
- 오블완
- MAC OSX 10.7
- 오브젝트 C
- MySQL
- 아이폰
- Object C
- Spring
- JSP
- Objective C
- Programming
- 아이폰 개발
- 아이폰 어플리케이션
- 오브젝티브 C
- Spring Framework
- Java
- zero
- SQL
- iBATIS
- oracle
- jQuery
- tomcat
- 티스토리챌린지
- JavaScript
- 제이쿼리
- IT
- 자바
- 자바스크립트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |