Skip to content

Instantly share code, notes, and snippets.

View inonb's full-sized avatar

Inoue Takayuki inonb

View GitHub Profile
@inonb
inonb / gist:3158884
Created July 22, 2012 08:17
[iOS] itemをDetailViewControllerに渡す
DetailViewController.h
@property (strong, nonatomic) NSDictionary *item;
DetailViewController.m
@synthesize item;
MasterViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
@inonb
inonb / gist:3158048
Created July 22, 2012 02:52
[iOS] アイコンをURLから取得する
// アイコンのプレースホルダを設定
cell.imageView.image = [UIImage imageNamed:@"placeholder"];
// アイコンのURLからリクエストを作る
NSString *iconURLString = [[[item objectForKey:@"im:image"] objectAtIndex:0] objectForKey:@"label"];
NSURL *iconURL = [NSURL URLWithString:iconURLString];
NSURLRequest *request = [NSURLRequest requestWithURL:iconURL];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@inonb
inonb / gist:3158036
Created July 22, 2012 02:48
[iOS] テーブルセルのプレースホルダ画像
・https://dl.dropbox.com/u/26298425/3daysiOSApp/placeholder.png
の画像をDL
・プロジェクトに追加(ファイルをナビゲータエリアにドラッグ)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// セルの初期化などの後に…
cell.imageView.image = [UIImage imageNamed:@"placeholder"];
@inonb
inonb / gist:3157988
Created July 22, 2012 02:31
[iOS] JSONをパースして配列を取得・テーブルビューに表示
- (void)viewDidLoad
{
[super viewDidLoad];
// 空の配列を用意
self.items = [NSArray array];
[self getJSON];
}
@inonb
inonb / gist:3157855
Created July 22, 2012 01:18
[iOS] 配列と辞書
// 配列を作る
NSArray *iphones = [NSArray arrayWithObjects:@"iPhone3G", @"iPhone3GS", @"iPhone4" nil];
// 配列から要素を取り出す
NSString *item2nd = [iphones objectAtIndex:2];
NSLog(item2nd); // ログに iPhone4
// 辞書を作る
NSDictionary *macbookair = [NSDictionary dictionaryWithObjectsAndKeys:
@"1.7GHz", @"cpu",
@inonb
inonb / gist:3150068
Created July 20, 2012 10:32
[iOS] URLからデータを取得
- (void)getURL
{
// URLクラスを作る
NSURL *url = [NSURL URLWithString:@"http://apple.com"];
// リクエストを作る
NSURLRequest *request = [NSURLRequest requestWithURL:url];
// 接続してデータを取得
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
@inonb
inonb / gist:3150013
Created July 20, 2012 10:16
[iOS] フィード例
さまざまなフィード
Amazon ベストセラーランク(RSS)
http://www.amazon.co.jp/gp/rss/bestsellers/books/ref=zg_bs_books_rsslink
YouTube - ColdPlay公式チャンネル(RSS)
http://gdata.youtube.com/feeds/base/users/ColdplayTV/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile
Apple Store - ニュース(JSON)
http://itunes.apple.com/jp/rss/topfreeapplications/limit=10/json

@inonb
inonb / gist:3069083
Created July 8, 2012 02:42
[iOS] テーブルビューの遷移
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// セルのタイトルを取得
NSString *name;
if (indexPath.row == 0) {
name = @"name01";
} else if (indexPath.row == 1) {
name = @"name02";
} else if (indexPath.row == 2) {
name = @"name03";
@inonb
inonb / gist:3046652
Created July 4, 2012 10:35
[iOS] URLを開く
// SafariでURLを開く
NSURL *urlSafari = [NSURL URLWithString:@"https://twitter.com/"];
[[UIApplication sharedApplication] openURL:urlSafari];
// Mailでメールを送る
NSURL *urlMail = [NSURL URLWithString:@"mailto:inouetakayuki@gmail.com"];
[[UIApplication sharedApplication] openURL:urlMail];
@inonb
inonb / gist:3038599
Created July 3, 2012 08:54
[iOS] イメージビューのIBOutlet作成と画像の表示
// ViewController.h に IBOutlet を作成
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
// ViewController.m で 画像をセット
//(あらかじめ image_name.png をプロジェクトに追加)
self.imageView.image = [UIImage imageNamed:@"image_name"];