「Xcode」タグアーカイブ

ボタンを押すと画像表示 [UIImageView]

スクリーンショット 2013-10-29 23.40.59

Main.storyboardに 「image View」と「botton」を配置

ViewController.hにコネクト
[php]

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIImageView *myImageView;
– (IBAction)topBtn:(id)sender;
@end
[/php]

ViewController.mにボタンアクションを設定
[php]
– (IBAction)topBtn:(id)sender {
_myImageView.image = [UIImage imageNamed:@"child02.png"];
}
[/php]

ボタンでアクションをさせるよ [UIActionSheet]

スクリーンショット 2013-10-29 22.18.33

Main.storyboudにボタンをラベルを配置

ViewController.hにボタン/ラベルを入れる
[php]
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIActionSheetDelegate>{
}
@property (strong, nonatomic) IBOutlet UILabel *mylabel;
– (IBAction)btn:(id)sender;

@end
[/php]

ViewController.mにボタンを配置とアクションを追加
[php]
– (IBAction)btn:(id)sender {
UIActionSheet *actionSheet =
[[UIActionSheet alloc] initWithTitle:@"テストタイトル"
delegate:self
cancelButtonTitle:@"キャンセル"
destructiveButtonTitle:@"タイトル"
otherButtonTitles:@"処理1",@"処理2", nil];
[actionSheet showInView:self.view]; //呼び出し
}

– (void)actionSheet:(UIActionSheet *)actionSheet
clickedButtonAtIndex:(NSInteger)buttonIndex{
_mylabel.text =
[NSString stringWithFormat:@"ボタン",buttonIndex];
}
@end
[/php]

viewDidLoad viewWillAppear viewDidAppear viewWillDisappear viewDidDisappear

init(インスタンス作成時に呼び出したイニシャライザ)
  ↓
viewDidLoad
 ・View が初めて呼び出される時に1回だけ呼ばれます。
 ・アプリ起動後に初めて当Viewが表示された場合に1度だけ呼ばれます。
  ↓
viewWillAppear
 ・View が表示される直前に呼ばれるメソッド
 ・タブ等の切り替え等により、画面に表示されるたびに呼び出されます。
 ・タブが切り替わるたびに何度でも呼ばれます。
  ↓
viewDidAppear
 ・View の表示が完了後に呼び出されるメッソド
 ・タブ等の切り替え等により、画面に表示されるたびに呼び出されます。
 ・タブが切り替わるたびに何度でも呼ばれます。
  ↓
viewWillDisappear
 ・View が他のView (画面から消える) 直前に呼び出されるメッソド
 ・View が他のView (画面から消える) 直前に呼び出されるメッソド
 ・タブが切り替わるたびに何度でも呼ばれます。
  ↓
viewDidDisappear
 ・View が他のView (画面から消えた) 非表示後に呼び出されるメッソド
 ・View が他のView (画面から消える) 直前に呼び出されるメッソド
 ・タブが切り替わるたびに何度でも呼ばれます。

引用サイト
http://blog.77jp.net/iphone%E9%96%8B%E7%99%BA-uiviewcontroller-%E3%83%A9%E3%82%A4%E3%83%95%E3%82%B5%E3%82%A4%E3%82%AF%E3%83%AB-viewdidload-viewwillappear-viewdidappear-viewwilldisappear-viewdiddisappear-ios-%E9%80%86

cocos2d-iphone-2.1をインストール

cocos2d-iphoneをダウンロード
https://code.google.com/p/cocos2d-iphone/downloads/list

cocos2d-iphone-2.1.tar.gzが最新のようなので、ダウンロードします。

「ターミナル」を起動して、以下のコマンドを入力

①Downloadsにファイルが入っているのでDownloadsに移動
[php]
$ cd ~/Downloads
[/php]
②解凍します。
[php]
$ tar xzvf cocos2d-iphone-2.1.tar.gz
[/php]
③解凍後で出来たディレクリへ移動
[php]
$ cd cocos2d-iphone
[/php]
④cocos2d-iphoneディレクリの中のファイルinstall-templates.shを実行
[php]
$ ./install-templates.sh
[/php]

Xcodeを起動し、テンプレートが出来ていればインストール完了

ViewControllerの書き方

①「ViewController.h」に
[php]
//————————————————-//
//フレームワークをインポート
//————————————————-//
#import <UIKit/UIKit.h>

//————————————————-//
//クラスとインスタンス変数の宣言
//————————————————-//
@interface ViewController : UIViewController <UIAlertViewDelegate,UIActionSheetDelegate>

//————————————————-//
//アクセサメソッドの宣言を
//————————————————-//

//————————————————-//
//オリジナルメソッドの宣言
//————————————————-//
– (void)configureView;
– (void)alertOKCancel;
– (void)actionOKCancel;

//————————————————-//
//ヘッダーファイル
//————————————————-//
@end

[/php]

②ViewController.m
[php]
/————————————————-//
//ヘッダーファイルをインポート
//————————————————-//
#import "ViewController.h"

@interface ViewController ()
@end

//————————————————-//
//クラスとアクセサメソッドの実装
//————————————————-//
@implementation ViewController

//————————————————-//
// 処理
//————————————————-//
– (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

// ビューの設定をまとめて行うメソッドを呼び出します。
[self configureView];
}

//————————————————-//
// ビュー[.hのオリジナルメソッド]
//————————————————-//
– (void)configureView
{
UIButton *customButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
customButton1.frame = CGRectMake(40.0, 100.0, 240.0, 40.0);
[customButton1 setTitle:@"アラート" forState:UIControlStateNormal];
[customButton1 addTarget:self action:@selector(alertOKCancel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customButton1];

UIButton *customButton2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
customButton2.frame = CGRectMake(40.0, 180.0, 240.0, 40.0);
[customButton2 setTitle:@"アクションシート" forState:UIControlStateNormal];
[customButton2 addTarget:self action:@selector(actionOKCancel) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customButton2];
}

//————————————————-//
// [.hのオリジナルメソッド]
//————————————————-//
– (void)alertOKCancel
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"アラート"
message:@"よろしいですか?"
delegate:self
cancelButtonTitle:@"いいえ"
otherButtonTitles:@"はい", nil];
[alert show];
}

– (void)actionOKCancel
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"アクションシート"
delegate:self
cancelButtonTitle:@"いいえ"
destructiveButtonTitle:@"はい"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
}

//————————————————-//
// デリゲートメソッド
//————————————————-//
– (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

– (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"『%d番』のボタンが押されました!",buttonIndex);
}

– (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"『%d番』のボタンが押されました!",buttonIndex);
}

//————————————————-//
// メソッドファイルend
//————————————————-//
@end

[/php]