がるの健忘録

エンジニアでゲーマーで講師で占い師なおいちゃんのブログです。

あいふぉんあぷりのちっぷすとかなうりっぢとか

memoと呼ぶのすら烏滸がましいような物体。
後でまとめますんで orz
書きためてたけどこのタイミングで消えるとめっさブルーなので、とりあえず第一陣あっぷ。


// viewセットを切り替える;画面遷移

(UIWindow *)window->addSubview(view *v)


// viewインスタンスの取得方法例

(view *v)v = (UIViewController *)obj->view();
(view *v)v = (UINavigationController *)obj->view();


Navigationについて。
viewインスタンスLIFOでしまい込んで画面遷移、って発想はおもころいかも。


//
view作ってcontrollerの継承にして
Cocoa touch class -> UIVewController subclassを作成
MainWindow.xilをclickしてNavigationControll内のTop controllerをクリック、Inspectorの一番右、classを「UIVewController subclassを作成」で作ったクラス名に割り当てる
…何に使うか今ひとつわからんが。いやわかった。
「対象のview(Window)の処理はこのサブクラスの中にしか書けない;特にAction系の処理」ってことだ。
んで。例えば一つの遷移例。…戻る処理は書かなくてもよいっぽ。すげぇなぁ。

-(IBAction)actionNavigate:(id)sender {
	UIViewController *tController = [[UIViewController alloc] initWithNibName:@"nextPage" bundle:[NSBundle mainBundle]];
	
	NSLog(@"clicked !!");
	
	if (nil != tController) {
		[[self navigationController] pushViewController:tController animated:YES];
		[tController release];
	}
}

@"nextPage" ンところには、必要なお名前を。
珍しくちゃんと「作ったファイル名と対比させるしかない」という安心設計。


// デバッグ向け

NSLog()
%@
%d


//
tableの出力
1.UITableViewControllerの継承クラスを作る
2.init、またはinitWithStyle(今回はこっち)で、腹に「出力するデータ一式」抱え込むと楽
3.おそらく「rowの数」を規定してると予測されるメソッド。magic numberはやめておきませう。managerってのは、今回、データを総括でもってるインスタンス。array系。

// Customize the number of rows in the table view.
 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [manager countOfData];
 }

4.1cellごとにcallされると思われるメソッド。1行の処理はまぁここで。

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Set up the cell...
    cell.textLabel.text = [[manager loadAtIndex:indexPath.row] name];

    return cell;
}

ぶっちゃけ。「Set up the cell...」直前まではすでに書かれているので、その後ろを書くだけ。
画像ならimageView。インスタンスなので、例えばこんな感じのが雑で便利だよね。

UIImageView *obj = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hogeramugera.png"]];


UITableViewControllerはUIViewControllと同格(継承クラス)なので。
画面遷移先がtable、って感じなら、普通にNavigationにぶちこめば無問題〜
いわゆる一つのonClickイベントは
didSelectRowAtIndexPath
で取得。引数のindexPathに行数が入る感じ。


URIによる移動遷移。
例えば「狩猟を目的とした遠征」なブラウザで動かすならこんなげ。

NSURL *url = [NSURL URLWithString:@"http://d.hatena.ne.jp/gallu/"];
[[UIApplication sharedApplication] openURL:url];

また。
こちら( http://7kamura.blogspot.com/2009/09/iphoneopenurl.html )には、少々色々と別件が載っている。

メールアプリとの連携

    UIApplication *app = [UIApplication sharedApplication];
    NSString *to = @"to@test.jp"
    NSString *cc = @"cc@test.jp"
    NSString *bcc = @bcc@test.jp"
    NSString *subject = [[NSString stringWithFormat:@"テスト" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *body = [[NSString stringWithFormat:@"テスト
    送信
    です。"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *str = [NSString stringWithFormat:@"mailto:%@?cc=%@&bcc=%@&subject=%@&body=%@",to, cc, bcc, subject, body];
    [app openURL:[NSURL URLWithString:str]];

Phoneコールとの連携

    UIApplication *app = [UIApplication sharedApplicatoin];
    [app openURL:[NSURL URLWithString:@"tel:X-XXX-XXX-XXXX"]];
    // すぐ電話がかかるので注意

SMSとの連携

    UIApplication *app = [UIApplication sharedApplication];
    [app openURL:[NSURL URLWithString:@"sms:X-XXX-XXX-XXXX"]];

YouTubeとの連携

    UIApplication *app = [UIApplication sharedApplication];
    [app openURL:[NSURL URLWithString:@"http://www.youtube.com/v/ZGvfW2alYiA"]];

AppStoreのとの連携

    UIApplication *app = [UIAppliaction sharedApplication];
    [app openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=301175384&mt=8"]];