カテゴリー : Objective-C

[Objective-C] switch 文で Expected expression エラー

Objective-C の switch 文で Expected expression エラーが発生しました。

switch(i){
    case 0:
        int spam = 0;
        break;
    default:
        break;
}

case の中で変数宣言すると Expected expression エラーが出るので、以下のように変数宣言を switch文の外に書くとエラーが出なくなります。

int spam;
 
switch(i){
    case 0:
        spam = 0;
        break;
    default:
        break;
}

[参考]

Expected expressionというエラーがでる | 人生休暇中

[Objective-C][iOS] TabBar(タブバー)の実装方法

iPhone/iPadアプリ開発で、TabBar(タブバー)の実装方法を調べたのでメモ。

この辺を読む。

xcode4.2でStorybordを使わずにtabBarControllerにnavigationControllerを追加する方法 – tmplog はてなブックマーク - xcode4.2でStorybordを使わずにtabBarControllerにnavigationControllerを追加する方法 - tmplog

Bugle Diary: [Objective-C][iPhone sdk]tabbarの実装 はてなブックマーク - Bugle Diary: [Objective-C][iPhone sdk]tabbarの実装

頭と尻尾はくれてやる! タブ+ナビゲーションでタイトルとアイコンの設定 はてなブックマーク - 頭と尻尾はくれてやる! タブ+ナビゲーションでタイトルとアイコンの設定

UITabBarController – iPhoneアプリ開発の虎の巻 はてなブックマーク - UITabBarController - iPhoneアプリ開発の虎の巻

UINavigationController – iPhoneアプリ開発の虎の巻 はてなブックマーク - UINavigationController - iPhoneアプリ開発の虎の巻

以上です。

[Objective-C][iOS] unable to dequeue a cell with identifier Cell – must register a nib or a class for the identifier or connect a prototype cell in a storyboar

iOSアプリ開発にて、UITableView でエラー発生。

■ エラーメッセージ

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘unable to dequeue a cell with identifier Cell – must register a nib or a class for the identifier or connect a prototype cell in a storyboard’

■ 解決方法

indexPathに対応するCellのUIが取得できないので、indexPath指定せずに、後で値を取得するように修正すればOKです。

//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; //これだと実行時エラー
 
    static NSString *CellIdentifier = @"Cell";
 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

【参考】:UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション #iOS #Objective-C – Qiita はてなブックマーク - UITableView dequeueReusableCellWithIdentifier:forIndexPath: でのアサーション #iOS #Objective-C - Qiita

[iOS] Facebook や Path のようなスライドメニューを実装するライブラリ「IIViewDeckController」

iOS にて、Facebook や Path のようなスライドメニューを実装するライブラリ「IIViewDeckController」が便利そうなのでメモ。

Inferis/ViewDeck はてなブックマーク - Inferis/ViewDeck

Path や Facebook ライクなスライドメニューを実現するライブラリ “IIViewDeckController” – Over&Out その後 はてなブックマーク - Path や Facebook ライクなスライドメニューを実現するライブラリ

Path や Facebook ライクなスライドメニューを実現するライブラリ7種を比較! – Over&Out その後 はてなブックマーク - Path や Facebook ライクなスライドメニューを実現するライブラリ7種を比較! - Over&Out その後

以上です。

[Objective-C] UICollectionView の使い方

iOS6 から使えるようになった UICollectionView の使い方の参考情報をメモ。

UICollectionView Class Reference はてなブックマーク - UICollectionView Class Reference

[iOS6] Collection View 基本的な使い方 – iOS 開発ブログ Natsu’s note はてなブックマーク - [iOS6] Collection View 基本的な使い方 - iOS 開発ブログ Natsu's note

iOS6 UICollectionViewを使ってみる | クラスメソッド開発ブログ はてなブックマーク - iOS6 UICollectionViewを使ってみる | クラスメソッド開発ブログ

iOS5 では PSTCollectionView というライブラリを使うか、変態的なことをして使えるようにする。

ONETOPI – steipete/PSTCollectionView GitHub はてなブックマーク - ONETOPI - steipete/PSTCollectionView GitHub

UICollectionViewCellのサブクラスをiOS 5で共存させる | HMDT Blog はてなブックマーク - UICollectionViewCellのサブクラスをiOS 5で共存させる | HMDT Blog

以上です。

[Objective-C] unrecognized selector sent to instance

Objective-C にて下記のようなエラーに遭遇。

unrecognized selector sent to instance

原因は色々とあるみたいですが、今回はメソッドの引数に値がちゃんと渡っていなかったせいでした。

・参考:iOS開発で遭遇した謎のエラーたち | ひげろぐ はてなブックマーク - iOS開発で遭遇した謎のエラーたち | ひげろぐ

[Objective-C] Instance method -initWithfloat not found return type defaults to id

Objective-C で下記のようなメソッドが見つからないというエラーが発生して、悩んでいました。

原因は分かってしまえば単純なもので、正しくは initWithFloat なのを initWithfloat とタイポしていただけでした。

■ エラーメッセージ

Instance method -initWithfloat not found return type defaults to id

これに数時間費やしたと思うと…。

この辺、読んでやっと気付きました。ありがたや。

floatからNSNumber作るやり方:三浦仮想研究所 はてなブックマーク - floatからNSNumber作るやり方:三浦仮想研究所

S4U -smile for you-: Instance method ‘-resizedImage:’ not found (return type defaults to ‘id’) はてなブックマーク - S4U -smile for you-: Instance method '-resizedImage:' not found (return type defaults to 'id')