2014年5月1日木曜日

UITableView、forIndexPath:indexPathを付けるとdequeueReusableCellWithIdentifier:@hogeが失敗する


チュートリアルなんかでよくみるやーつ

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    [self configureCell:cell atIndexPath:indexPath];
    return cell;
}

この通りにしても…

*** 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'

と落ちてしまいハマることがある。
ぐぐると、PrototypeCellにIdentifer設定してる?みたいな話か(当然してますよねー)
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)...
と、forIndexPathを切って、作れてなければ作ればいいんだよ。
って解決方法ばかり出てくる。
実際まあこれで解決することもあるんだけど、なんか、もやーん。

そんなとき、あと1個だけチェックしてみません?
そのエラーのでるビュー、こんな感じでStoryBoardで作ったものを手動で作ってたりする場合。

ErrorDeruViewController *view = [[ErrorDeruViewController alloc]init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];
nav.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:nav animated:YES completion:nil];


古めの記事なんかでは、モーダル表示するのはこうですって紹介されてたりするので
コピペるとハマります。
こういう呼び方をすると、Storyboardとカスタムクラスが結び着かないので
そんなIdentiferのついたCellが見つからないけど…ってことで落ちてるみたいです。
なので

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ErrorDeruViewController *view = [storyBoard instantiateViewControllerWithIdentifier:@"ErrorDeruViewControllerId"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:view];
nav.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;

[self presentViewController:nav animated:YES completion:nil];


みたいな感じで、StoryBoardからviewのインスタンスを作ってあげればOKです。
該当のViewControllerには、StoryBoard上でStoryboardIDを設定してあげましょう。
(上記のErrorDeruViewControllerIdのところ)

※注意:iOS6以前に対応する場合には、forIndexPathをとっぱらう方法で対応しましょう。そこは仕様上の制限です。

          /~~~~,
          /おしまい /
         /~~~~'
     / ̄ ̄\
    ./   ヽ_   \
   (●)(● )    |
   (__人__)     |
   ヽ`⌒´     |
    {         |
    {       ノ
    ヽ     ノ
   /      ヽ

2014年4月18日金曜日

UIToolBar上のUIBarButtonItemを一時的に非表示にする

どうも
self.toolBarItemsから一時的に削除するのが筋らしいけど、なんか気持ち悪い。

で。

if(ButtonVisible)
{
    self.BarButtonRef.tintColor = nil;
    [self.BarButtonRef setEnabled:YES]
} else {
    self.BarButtonRef.tintColor = [UIColor colorWithWhite:0 alpha:0];
    [self.BarButtonRef setEnabled:NO]
}

注意点
・BarButtonRefってあるところはアウトレットするか、toolBarItemsから取得しておきます。
・デフォルトカラーじゃない場合はnilんとこ直します。





          /~~~~,

          /おしまい /
         /~~~~'
     / ̄ ̄\
    ./   ヽ_   \
   (●)(● )    |
   (__人__)     |
   ヽ`⌒´     |
    {         |
    {       ノ
    ヽ     ノ
   /      ヽ

2014年2月20日木曜日

PocketでFavoriteしたページの全文をEvernoteに自動で保存する 2014年2月版

多々事情により面倒ですよね。


準備するもの

  • IFTTTアカウント
  • Deliciousアカウント(できればまっさらなの)
  • yahoo.comアカウント(タグ不要なら省略)
  • もちろんEvernoteとPocketも


まず結論

  1. IF [PocketのFavoriteが追加] Then [Deliciousに追加]
  2. Deliciousの情報をRSSで取得
  3. fullrss.netで全文化
  4. Yahoo!Pipesでタグを入れ替え
  5. IF [Rss] Then [Evernoteに保存]
そう。超遠回り。


説明

fullrss.netで全文化するにはRSSが必要

PocketのFavoriteを取得するには、IFTTT経由しかない(RSSは未読・既読のみ)

IFTTTのRSSトリガーには、Categoryを取得する方法がない

遠回りが必要


詳細

1.IF [PocketのFavoriteが追加] Then [Deliciousに追加]

こんな感じのを作る


あとでrssのdescriptionに適用されるように、Notesに{{Tags}}を埋め込む


2.Deliciousの情報をRSSで取得

ドキュメント漁ったりで
http://feeds.delicious.com/v2/rss/ユーザー名



3.fullrss.netで全文化

こんな感じになるはず
http://fullrss.net/a/http/feeds.delicious.com/v2/rss/ユーザ名


4.Yahoo!Pipesでタグを入れ替え

イレギュラーだけどこんな感じに


authorにdescriptionを転送する。
できたrssをめもめも。
http://pipes.yahoo.com/pipes/pipe.run?_id=[できたID]&_render=rss



5.IF [Rss] Then [Evernoteに保存]

rssをEvernoteに。



さっきAuthorに入れたTagsがEntryAuthorで送られてくるので

Tagsとして再パース。





          /~~~~,

          /おしまい /
         /~~~~'
     / ̄ ̄\
    ./   ヽ_   \
   (●)(● )    |
   (__人__)     |
   ヽ`⌒´     |
    {         |
    {       ノ
    ヽ     ノ
   /      ヽ