Cocoa tutorial – linking and using libmysqlclient in your application

Here’s a little tutorial on how to use libmysqlclient in a Cocoa application.

First of all you need to create a new Xcode project; suppose to create it in the directory: /path/to/your/project/.

Then you need to retrieve the libmysqlclient.aand libmysqlclient_r.afiles located in the /usr/local/mysql/lib/default directory. To do this you can, for example, start a new Terminal session and type the following commands:

cp/usr/local/mysql/lib/libmysqlclient.a /path/to/your/project/cp/usr/local/mysql/lib/libmysqlclient_r.a /path/to/your/project/

Now go to Xcode and select “Project” -> “Edit Project Settings” in the main menu. Now select the “Build” tab and make the following changes to all your configurations (Debug and Release):

  • “Architectures”: the same of your libmysqlclient architecture;
  • “Valid Architectures”: architectures compatibles with your libmysqlclient architecture(s);
  • “C/C++ Compiler Version”: GCC 4.2;
  • uncheck “Prebinding”;
  • turn on (if desired) the “Objective-C Grabage Collection”;
  • “C Language Dialect”: C99 [-std=c99];
  • check “Mismatched Return Type”;
  • check “Unused Variables”.

Note that not all of these flags are strictly required for the correct use of libmysqclient.aand libmysqlclient_r.a; you can test them and see what happens when you change some of them.

Now you need to import the libraries. To do so, right click on the group “Frameworks” located in the “Groups & Files” tree in Xcode and select “Add” -> “Existing Frameworks…”. Locate the libmysqlclient.afile and click the Add button. Repeat the operation with the libmysqlclient_r.afile.

Now you need to tell Xcode to copy the two libraries in the bundle directory. To do so, you must create a new copy build phase in your target and put the libraries in it:

  • Expand the “Targets” group in the “Groups & Files” tree;
  • right click on your application and select: “Add” -> “New Build Phase” -> “New Copy Files Build Phase”;
  • in the new window select “Frameworks” in the Destination popup menu;
  • close the window;
  • drag and drop the libmysqlclient.aand libmysqlclient_r.afiles from the Frameworks group to the new “Copy Files” group.

Now you need to copy all the MySQL C API headers in your project directory. To do so you can, for example, do something like this:

cp-R/usr/local/mysql/include//path/to/your/project/mysql_include/

That’s all. To access any MySQL API function, you only need to import the mysql.hand unistd.h

Here’s a short example on how to use the API in a .m file:

... #include "mysql.h"#include "unistd.h"  @implementationAppController   ...   -(void)connect {MYSQL conn; mysql_init(amp;conn);   if(!mysql_real_connect(amp;conn, "127.0.0.1", "", "", "", 0, NULL, 0))NSLog(@"%s", [NSStringstringWithUTF8String:mysql_error(amp;conn)]); elseNSLog(@"Connected"); }@end

Download the test project.



출처 : http://blog.naver.com/PostView.nhn?blogId=ups999&logNo=150097675553
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 10. 15. 06:10
[아이폰 앱 개발] iPad for iPhone Developers 101: UIPopoverController Tutorial

iPad for iPhone Developers 101: UIPopoverController Tutorial

http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial

This is the second part of a three part series to help get iPhone Developers up-to-speed with iPad development by focusing on three of the most interesting new classes (at least to me): UISplitView, UIPopoverController, and Custom Input Views.

In the first part of the series, we made an app with a split view that displays a list of monsters on the left side, and details on the selected monster on the right side.

In this part, we’re going to try out popovers view with a simple example: we’ll add a popover to let the user select from a list of colors to change the color of the monster’s name.

We’ll start out with where we left off the project last time, so grab a copy if you don’t have it already.

Creating our Color Picker

Let’s start by creating the view that we’ll use to let the user pick between a list of colors. We’ll make this a simple table view with a list of color names.

So go to “File\New File…”, pick “UIViewController subclass”, and make sure “Targeted for iPad” and “UITableViewController subclass” are checked but “With XIB for user interface” is NOT checked, and click Next. Name the class ColorPickerController, and click Finish.

Then replace ColorPickerController.h with the following:


@protocol ColorPickerDelegate
- (void)colorSelected:(NSString *)color;
@end
 
 
@interface ColorPickerController : UITableViewController {
    NSMutableArray *_colors;
    id<ColorPickerDelegate> _delegate;
}
 
@property (nonatomic, retain) NSMutableArray *colors;
@property (nonatomic, assign) id<ColorPickerDelegate> delegate;
 
@end

Here we declare a delegate so that this class can notify another class when a user selects a color. We then declare two variables/properties: one for the list of colors to display, and one to store the delegate itself.

Then make the following changes to ColorPickerController.m:


// Under @implementation
@synthesize colors = _colors;
@synthesize delegate = _delegate;
 
// Add viewDidLoad like the following:
- (void)viewDidLoad {
    [super viewDidLoad];
    self.clearsSelectionOnViewWillAppear = NO;
    self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);
    self.colors = [NSMutableArray array];
    [_colors addObject:@"Red"];
    [_colors addObject:@"Green"];
    [_colors addObject:@"Blue"];
}
 
// in numberOfSectionsInTableView:
return 1;
 
// in numberOfRowsInSection:
return [_colors count];
 
// In cellForRowAtIndexPath, under configure the cell:
NSString *color = [_colors objectAtIndex:indexPath.row];
cell.textLabel.text = color;
 
// In didSelectRowAtIndexPath:
if (_delegate != nil) {
    NSString *color = [_colors objectAtIndex:indexPath.row];
    [_delegate colorSelected:color];
}
 
// In dealloc
self.colors = nil;
self.delegate = nil;

Most of this should be normal table view stuff except for the following line:


self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);

This line sets the size of how large the popover should be when it is displayed. If you do not add this line, by default the popover will be the entire height of the screen (which is usually too large).

Displaying the Picker

Believe it or not, that was the hardest part. Now to display the picker, all we need to do is add a button to our toolbar, and a little bit of code to display it and handle the selection.

So first, let’s add the button. Open up RightViewController.xib and add a Bar Button Item to the toolbar. Set the title of the button “Set Color”.

Now let’s declare a method for the button to trigger in RightViewController.h and declare a few variables we’ll need in a minute:


// Up top, under #import
#import "ColorPickerController.h"
 
// Modfiy class declaration
@interface RightViewController : UIViewController <MonsterSelectionDelegate,  
    UISplitViewControllerDelegate, ColorPickerDelegate> {
 
// Inside class
ColorPickerController *_colorPicker;
UIPopoverController *_colorPickerPopover;
 
// In property section
@property (nonatomic, retain) ColorPickerController *colorPicker;
@property (nonatomic, retain) UIPopoverController *colorPickerPopover;
 
- (IBAction)setColorButtonTapped:(id)sender;

Before we forget, go ahead and connect the action method to the Bar Button Item in Interface Builder by control-dragging from the Bar Button Item to File’s Owner and connecting to the “setColorButtonTapped” outlet.

Then let’s finish by making the required changes to RightViewController.m:


// In synthesize section
@synthesize colorPicker = _colorPicker;
@synthesize colorPickerPopover = _colorPickerPopover;
 
// In dealloc
self.colorPicker = nil;
self.colorPickerPopover = nil;
 
// Add to end of file
- (void)colorSelected:(NSString *)color {
    if ([color compare:@"Red"] == NSOrderedSame) {
        _nameLabel.textColor = [UIColor redColor];
    } else if ([color compare:@"Green"] == NSOrderedSame) {
        _nameLabel.textColor = [UIColor greenColor];
    } else if ([color compare:@"Blue"] == NSOrderedSame){
        _nameLabel.textColor = [UIColor blueColor];
    }
    [self.colorPickerPopover dismissPopoverAnimated:YES];
}
 
- (IBAction)setColorButtonTapped:(id)sender {
    if (_colorPicker == nil) {
        self.colorPicker = [[[ColorPickerController alloc] 
            initWithStyle:UITableViewStylePlain] autorelease];
        _colorPicker.delegate = self;
        self.colorPickerPopover = [[[UIPopoverController alloc] 
            initWithContentViewController:_colorPicker] autorelease];               
    }
    [self.colorPickerPopover presentPopoverFromBarButtonItem:sender 
        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

Ok let’s explain this a bit. All popovers are is a “wrapper” around an existing view controller that “floats” it in a certain spot and possibly displays an arrow showing what the popover is related to. You can see this in setColorButtonTapped – we create our color picker, and then wrap it with a popover controller.

Then we call a method on the popover controller to display it in the view. We use the helper function presentPopoverFromBarButtonItem to display the popover.

When the user is done, they can tap anywhere outside the popover to dismiss it automatically. However if they select a color, we also want it to be dismissed, so we call the dismissPopoverAnimated method to get rid of the popover on-demand (as well as setting the color appropriately).

And that’s it! Compile and run and when you tap the “Set Color” bar button item, you should see a popover like the following that changes the label color:

You will find yourself using popovers quite a bit in places where users need to edit a field or toggle a setting, rather than the iPhone style where you navigate to the next level in a UINavigationController. They call this “flattening the hierarchy” in the iPad docs.

Show Me the Code!

Here’s a copy of all of the code we’ve developed so far.

Check out the next part of the series, where we cover how to use custom input views on the iPad!

Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 10. 12. 05:36
iPad for iPhone Developers 101: UIPopoverController Tutorial

iPad for iPhone Developers 101: UIPopoverController Tutorial

http://www.raywenderlich.com/1056/ipad-for-iphone-developers-101-uipopovercontroller-tutorial

This is the second part of a three part series to help get iPhone Developers up-to-speed with iPad development by focusing on three of the most interesting new classes (at least to me): UISplitView, UIPopoverController, and Custom Input Views.

In the first part of the series, we made an app with a split view that displays a list of monsters on the left side, and details on the selected monster on the right side.

In this part, we’re going to try out popovers view with a simple example: we’ll add a popover to let the user select from a list of colors to change the color of the monster’s name.

We’ll start out with where we left off the project last time, so grab a copy if you don’t have it already.

Creating our Color Picker

Let’s start by creating the view that we’ll use to let the user pick between a list of colors. We’ll make this a simple table view with a list of color names.

So go to “File\New File…”, pick “UIViewController subclass”, and make sure “Targeted for iPad” and “UITableViewController subclass” are checked but “With XIB for user interface” is NOT checked, and click Next. Name the class ColorPickerController, and click Finish.

Then replace ColorPickerController.h with the following:


@protocol ColorPickerDelegate - (void)colorSelected:(NSString *)color; @end     @interface ColorPickerController : UITableViewController { NSMutableArray *_colors; id<ColorPickerDelegate> _delegate; }   @property (nonatomic, retain) NSMutableArray *colors; @property (nonatomic, assign) id<ColorPickerDelegate> delegate;   @end

Here we declare a delegate so that this class can notify another class when a user selects a color. We then declare two variables/properties: one for the list of colors to display, and one to store the delegate itself.

Then make the following changes to ColorPickerController.m:


// Under @implementation @synthesize colors = _colors; @synthesize delegate = _delegate;   // Add viewDidLoad like the following: - (void)viewDidLoad { [super viewDidLoad]; self.clearsSelectionOnViewWillAppear = NO; self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0); self.colors = [NSMutableArray array]; [_colors addObject:@"Red"]; [_colors addObject:@"Green"]; [_colors addObject:@"Blue"]; }   // in numberOfSectionsInTableView: return 1;   // in numberOfRowsInSection: return [_colors count];   // In cellForRowAtIndexPath, under configure the cell: NSString *color = [_colors objectAtIndex:indexPath.row]; cell.textLabel.text = color;   // In didSelectRowAtIndexPath: if (_delegate != nil) { NSString *color = [_colors objectAtIndex:indexPath.row]; [_delegate colorSelected:color]; }   // In dealloc self.colors = nil; self.delegate = nil;

Most of this should be normal table view stuff except for the following line:


self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);

This line sets the size of how large the popover should be when it is displayed. If you do not add this line, by default the popover will be the entire height of the screen (which is usually too large).

Displaying the Picker

Believe it or not, that was the hardest part. Now to display the picker, all we need to do is add a button to our toolbar, and a little bit of code to display it and handle the selection.

So first, let’s add the button. Open up RightViewController.xib and add a Bar Button Item to the toolbar. Set the title of the button “Set Color”.

Now let’s declare a method for the button to trigger in RightViewController.h and declare a few variables we’ll need in a minute:


// Up top, under #import #import "ColorPickerController.h"   // Modfiy class declaration @interface RightViewController : UIViewController <MonsterSelectionDelegate, UISplitViewControllerDelegate, ColorPickerDelegate> {   // Inside class ColorPickerController *_colorPicker; UIPopoverController *_colorPickerPopover;   // In property section @property (nonatomic, retain) ColorPickerController *colorPicker; @property (nonatomic, retain) UIPopoverController *colorPickerPopover;   - (IBAction)setColorButtonTapped:(id)sender;

Before we forget, go ahead and connect the action method to the Bar Button Item in Interface Builder by control-dragging from the Bar Button Item to File’s Owner and connecting to the “setColorButtonTapped” outlet.

Then let’s finish by making the required changes to RightViewController.m:


// In synthesize section @synthesize colorPicker = _colorPicker; @synthesize colorPickerPopover = _colorPickerPopover;   // In dealloc self.colorPicker = nil; self.colorPickerPopover = nil;   // Add to end of file - (void)colorSelected:(NSString *)color { if ([color compare:@"Red"] == NSOrderedSame) { _nameLabel.textColor = [UIColor redColor]; } else if ([color compare:@"Green"] == NSOrderedSame) { _nameLabel.textColor = [UIColor greenColor]; } else if ([color compare:@"Blue"] == NSOrderedSame){ _nameLabel.textColor = [UIColor blueColor]; } [self.colorPickerPopover dismissPopoverAnimated:YES]; }   - (IBAction)setColorButtonTapped:(id)sender { if (_colorPicker == nil) { self.colorPicker = [[[ColorPickerController alloc] initWithStyle:UITableViewStylePlain] autorelease]; _colorPicker.delegate = self; self.colorPickerPopover = [[[UIPopoverController alloc] initWithContentViewController:_colorPicker] autorelease]; } [self.colorPickerPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; }

Ok let’s explain this a bit. All popovers are is a “wrapper” around an existing view controller that “floats” it in a certain spot and possibly displays an arrow showing what the popover is related to. You can see this in setColorButtonTapped – we create our color picker, and then wrap it with a popover controller.

Then we call a method on the popover controller to display it in the view. We use the helper function presentPopoverFromBarButtonItem to display the popover.

When the user is done, they can tap anywhere outside the popover to dismiss it automatically. However if they select a color, we also want it to be dismissed, so we call the dismissPopoverAnimated method to get rid of the popover on-demand (as well as setting the color appropriately).

And that’s it! Compile and run and when you tap the “Set Color” bar button item, you should see a popover like the following that changes the label color:

You will find yourself using popovers quite a bit in places where users need to edit a field or toggle a setting, rather than the iPhone style where you navigate to the next level in a UINavigationController. They call this “flattening the hierarchy” in the iPad docs.

Show Me the Code!

Here’s a copy of all of the code we’ve developed so far.

Check out the next part of the series, where we cover how to use custom input views on the iPad!

Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:22
iPhone SDK Tutorial 뷰를 모달로 띄우기
2010.01.25 월요일
오늘 종일 불안한 마음으로 서성인 하루에 한가지 남는 수확이라 여긴게 이거다.
"한개의 윈도우 그리고 여러개의 뷰"
이게 아이폰 개발의 원칙(?)쯤이라 말할 수 있다. 그래서 몇일전부터 고민고민하던게 뭐냐면,
 
 
만들어놓은 뷰를 프로젝트마다 써먹을 수 있는 방법이 뭘까

UIView 는 동적으로 생성될 수 있지만, 일일이 그려가면서까지 만들고 싶은 마음은 없다.
XIB 파일에 넣어진 UIView 를 불러다 쓰는 방법을 고민한 결과
재밌게도 이 방식을 유튜브에서 동영상 튜토리얼로 찾아낼 수 있었다.

방법은 
1. 뷰베이스 어플리케이션을 만든다. [뷰베이스, 즉 메인뷰는 존재한다는 거다]
2. 모달로 띄울 뷰를 만든다. [UIViewController 의 Subclass 로 만드는거다]
3. 메인뷰에서 세컨뷰를 띄워본다. 아래 코드로

#import "SecondView.h"
@implementation SwitcherViewController
-(IBAction)goToSecondView:(id)sender {
SecondView *secondView = [[SecondView alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:secondView animated:YES];
}

4. 세컨뷰에서 메인뷰로 돌아가려면 아래 코드로

@implementation SecondView
-(IBAction)goBack:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}

너무너무 쉬워서 토할뻔 했다. 이걸 그렇게 찾아헤맸다니
유튜브 동영상 링크도 걸어놓자.
https://www.youtube.com/watch?v=coz6zaGEYSk




출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50081308768
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:22
iPhone SDK Tutorial 어플의 실행 순서

참 많이도 궁금했다. 실은 이런걸 먼저 습득한 후 개발에 들어가야 했었는데,

내가 알아낸건 앱이 최초 실행될 때의 과정에 대해서이다.

딜리게이트, XIB, 뷰, 뷰콘트롤러.. 그리고 이것들의 연결고리들.. 복잡해 보였기 때문에, 이 부분을 파는게 옳았다.

뷰에 관점을 두어야 한다.

뷰는 도화지다. 아니 화면이다. 사용자화면 말이다.

앱은 실행될 때 최초로 "화면에 뷰를 띄워야 한다" 는 것이다.

윈도우베이스로 프로젝트를 생성하고 실행시키게 되면 어떠한 뷰도 나타나지 않는다.

시뮬레이터에 보이는 것은 그냥 먹먹한 회색빛 화면이다.

따라서,

앱한테 최초에 어떤 뷰를 보여주어야 하는지 설정해줘야 한다. 이걸 어디서 하느냐면..

바로 딜리게이트에서 한다. 딜리게이트의 헤더에 뷰콘트롤러를 아웃렛으로 코딩해주고 구현부에서

해당 뷰콘트롤러가 가진 뷰를 윈도우의 뷰로 설정하라는 코드가 필요하다.

이하 헤더부

#import <UIKit/UIKit.h>

@interface SPWinBaseAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
UIViewController *viewContrller;
}

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

@end

이하 구현부

#import "SPWinBaseAppDelegate.h"

@implementation SPWinBaseAppDelegate

@synthesize window;
@synthesize viewContrller;

- (void)applicationDidFinishLaunching:(UIApplication *)application {   

    // Override point for customization after application launch
[window addSubview:viewContrller.view];
    [window makeKeyAndVisible];
}


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

그리고 인터페이스 빌더에서 MainWindow.XIB 를 열고 라이브러리로부터 뷰콘트롤러를 드래그 하여 추가한다.

이제 위에서 코딩한 뷰콘트롤러 아웃렛이 바로 이녀석임을 설정!! (난 사실 이 부분이 너무 알고 싶었던 거다. 후후)


자, 이제 끝인가? 아니다.

뷰콘트롤러를 딜리게이트에 연결해줬고, 델리게이트의 런치피니쉬 메소드에서 메인윈도우의 뷰로 설정도 해줬지만

정작 뷰콘트롤러는 아무런 뷰도 가지고 있지 않다.

라이브러리를 통해서 뷰콘트롤러에 "뷰" 콘트롤을 추가해주고 실제 UI 작업은 그곳에서 해야 한다.

뷰를 올려놓으면 위 그림처럼 뷰콘트롤이 뷰콘트롤러의 하위 콘트롤로 생성이 되며, 그곳에 아무 라벨이나 올려놓고 실행해보자.




출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50081347132
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:22
iPhone SDK Tutorial 데이터 읽고 쓰기
파일을 읽고 쓰기...?
어떤 프로그래밍에서든 빠질 수 없는 부분이다.

예상대로 XML 형태의 데이터값들을 저장하고 읽는 방식으로 제공되고 있다.
바이너리라면 Base64 인코딩해서 XML 에 넣어야 할걸 ^^;;
일단 파일의 경로를 구하는 방법이다.
이걸 절대경로를 이용하는 방법은 절대 비추이다. 샌드박스의 절대경로를 알 수도 없을 것이다.
백북에서 시뮬레이터로 작업할 때 생기는 경로는 
/Users/nshc/Library/Application Support/iPhone Simulator/User/Applications 이다.

- (NSString *)dataFilepath {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

return [documentsDirectory stringByAppendingPathComponent:@"data.plist"];

}


위 메소드를 통해서 파일 경로를 구하거나 지정하고 ^^;;; 아래 메소드는 읽는 부분이 되겠다.


- (void)viewDidLoad {

NSString *filePath = [self dataFilepath];

if ([[NSFileManagerdefaultManager] fileExistsAtPath:filePath]) {

NSArray *array = [[NSArrayalloc] initWithContentsOfFile:filePath];

//NSLog(@"파일값: %@", [array objectAtIndex:0]);

[array release];

} else {

//NSLog(@"파일없음 data.plist");

}

    [superviewDidLoad];

}


보면 알겠지만 array 를 이용하고 있는데 이 array 라는 녀석이 만능이다.

맥환경에서의 설정파일은 XML 형태를 이용하는 plist 파일이 일반적인데, 이 파일을 array 형태로 읽고 쓰기가 가능하다.

쓰기는 어떻게 할까?


- (void)saveData:(NSString *)pValue {

NSMutableArray *array = [[NSMutableArrayalloc] init];

[array addObject:pValue];

[array writeToFile:[self dataFilepath] atomically:YES];

[array release];

//NSLog(@"파일저장완료");

}


어때? 이 심플함이 매력이다. array 가 writeToFile 메소드를 제공하고 있다규~ 오예~!!

실은 이 파일의 내용은 어플이 마지막으로 실행된 정보를 저장하거나 읽기 위해 기록한 데이터인데..


마지막으로..

array 객체가 아닌 키-밸류 형태의 데이터 저장과 읽기 방법은 NSDictionary 객체를 이용하는데 방법은 아래와 같다.

- (void)readPlist
{
    NSString *filePath = @"/System/Library/CoreServices/SystemVersion.plist";
        NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

        NSString *value;
        value = [plistDict objectForKey:@"ProductVersion"];
}

위에께 읽기 메소드고 쓰기는

- (void)writeToPlist
{
    NSString *filePath = @"/System/Library/CoreServices/SystemVersion.plist";
        NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];

        [plistDict setValue:@"1.1.1" forKey:@"ProductVersion"];
        [plistDict writeToFile:filePath atomically: YES];

}



출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50081533054
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:21
iPhone Tutorial - nib 에서 불러온 뷰를 특정위치에 모달로 띄우는 방법
- (void)showmodal:(UIView*)pParentView {

    UIView* modalView = [self view];
    
    CGPoint middleCenter = modalView.center;
    CGSize offSize = [UIScreen mainScreen].bounds.size;
    CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, -300);
    
    modalView.center = offScreenCenter; // we start off-screen
    [pParentView addSubview:modalView];
    
    // Show it with a transition effect
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.9]; // animation duration in seconds
    modalView.center = middleCenter;
    [UIView commitAnimations];
}

- (IBAction)hideModal
{    
    CGSize offSize = [UIScreen mainScreen].bounds.size;
    CGPoint offScreenCenter = CGPointMake(offSize.width / 2.0, -300);
    [UIView beginAnimations:nil context:[self view]];
    [UIView setAnimationDuration:0.9];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(hideModalEnded:finished:context:)];
    [self view].center = offScreenCenter;
    [UIView commitAnimations];
}
                                          
- (void) hideModalEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{    
    UIView* modalView = (UIView *)context;
    [modalView release];



출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50084523871
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:21
iPhone Tutorial - 투명한 뷰 띄우기
뷰를 띄우는 쪽에서는 이런식으로. 중요부분은 백그라운드칼라를 재지정하는 것이다.
   
SeconViewController *viewctrl = [[SeconViewController alloc] initWithNibName:nil bundle:nil];
[viewctrl view].backgroundColor = [UIColor clearColor];
[self.view addSubview: viewctrl.view];

뷰를 닫는쪽은 띄워진 뷰다.
[[self view] removeFromSuperview];

근데, 이걸 알아내는데 고생을 한 배경이
뷰를 띄울때
[self presentModalViewController:viewctrl animated:YES];
이런 식으로 띄우면 절대 통하지 않는다는거다.



출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50084528217
Posted by 오늘마감

댓글을 달아 주세요

아이폰어플개발정보2010. 6. 24. 14:21
iPhone Tutorial - TouchXML 사용법
TouchXML 을 사용하기 위해서는 프로젝트에 TouchXML 라이브러리를 추가해야 한다.
방법은..
1. TouchXML 소스를 프로젝트에 추가한다. 다운로드
2. TouchXML 은 lib2 를 사용하기 때문에 이를 프로젝트 콘피그에 설정해줘야 한다.
  • Setting 항목의 Search Paths 그룹의 Header Search Paths에 /usr/include/libxml2 값 설정.
  • Setting 항목의 Linking 그룹의 Other Linker Flags에 -lxml2 값 설정


이제 코딩으로 들어가보자.
사용하기 위해 임포트 먼저 하고
#import "TouchXML.h"

그리고 XML 파일을 읽어야겠지?
- (IBAction)doTouchXML {
   
    NSBundle* bundle = [NSBundle mainBundle];
    NSString* strXMLFIlePath = [bundle pathForResource:@"book" ofType:@"xml"];
    NSData *ndXMLFromFile = [[[NSData alloc] initWithContentsOfFile:strXMLFIlePath] autorelease];
   
    CXMLDocument *xmlParser = [[[CXMLDocument alloc] initWithData:ndXMLFromFile
                                                          encoding:NSUTF8StringEncoding options:0 error:nil] autorelease];

    NSArray *arrXmlNode = [xmlParser nodesForXPath:@"//book" error:nil];
    NSLog(@"BOOK COUNT: %d", [arrXmlNode count]);

CXMLDocument 객체를 이용해서 XML 파일을 읽어들이고 있다. 그리고는
XPathQuery 를 날려서 이를 배열로 받는데 각 배열안에 들어있는 오브젝트는 CXMLElement 이라는 자료형이다.




출처 : http://blog.naver.com/PostView.nhn?blogId=suny4rang&logNo=50084951521
Posted by 오늘마감

댓글을 달아 주세요