Railsでredirect_toでアクションを呼び出す
redirect_toでアクションを呼び出すことが出来る.
現在のコントローラのアクションを引数つきで呼び出す.引数は省略可能
redirect_to :action => :show, :id => 1
別のコントローラのアクションを呼び出す.
redirct_to :controller => "users", :action => :index
UITableViewの使い方
ViewControllerをUITableViewDelegateとUITableViewDataSourceに準拠させておく
viewDidLoad内でUITableViewのDelegateとDataSourceをselfに設定
以下のメソッドを実装
- didSelectRowAtIndexはセルの選択時に呼び出される.segueを呼び出すなどの処理を行う.
- numberOfRowsInSectionは セクション内のテーブル数を設定する(実装必須)
- cellForRowAtIndexはセルの中身を設定する(実装必須)
#pragma mark -- Table View Delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"Selected"); } #pragma mark -- Table View DataSoruce - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } if (indexPath.row == 0) { cell.textLabel.text = @"foo"; } else if (indexPath.row == 1) { cell.textLabel.text = @"bar"; } else if (indexPath.row) { cell.textLabel.text = @"hoge"; } return cell; }
UIActionSheet
UIActionSheetを使うには,
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Upload" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"DropBox", @"Evernote", nil]; [actionSheet showInView:self.view];
Objective-Cで画面キャプチャ
UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
QuartzCore/QuartzCore.hのインポートが必要
Objective-Cで別スレッドで処理
バックグラウンドスレッドで処理を行いたい場合は
[self performSelectorInBackground:@selector(method) withObject:nil];
を用いる.withObjectにはメソッドの引数を指定する. メインスレッド(画面の描画を行っているスレッド)上での遅延実行は
[self performSelector:@selector(method) withObject:nil afterDelay:1000];
を用いる. このselfはたしかAppDelegeteだったはず.
webアプリにACEエディタを埋め込む方法
ブラウザ上で動作するエディタにACEエディタがあります. これはCloud9IDEの一部でJavaScriptで書かれたエディタです.
準備としてGithubからACEのJavaScripファイルをダウンロードしてください. https://github.com/ajaxorg/ace-builds
src-min-noconflictフォルダをhtmlと同じディレクトリに配置し,以下のHTMLを実行してください.
<!DOCTYPE html> <html lang=en,ja> <header> <meta charset="utf8"> <title>ACE Editor</title> <style type="text/css" media="screen"> #editor { position: absolute; top: 0; right: 0; bottom: 0; left: 0; } </style> </header> <body> <div id="editor"> </div> <script src="./src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"> </script> <script> var editor = ace.edit("editor"); editor.setTheme("ace/theme/monokai"); editor.getSession().setMode("ace/mode/javascript"); </script> </body> </html>