• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

UITabBarController を使っていて、タブが6個以上になると自動的に「more」(plist の Localization native development region の値により文言は変化)というタブが現れ、そのテーブルビュー経由で5番目以降のビューはアクセスされる。

すなわち5番目以降のビューは UINavigationView aware でなくてはならない。

で、more に戻る backBarButtomItem をカスタマイズの仕方。

self が UITabBarController だとして

方法1、文言だけの変更

   1  	self.moreNavigationController.rootViewController.title = @"HOKA";
   2  

方法2、イメージを貼る

   1  	self.moreNavigationController.rootViewController.navigationItem.backBarButtonItem = [ [ [ UIBarButtonItem alloc ] initWithImage:[ UIImage imageNamed:@"0.png" ] style:UIBarButtonItemStyleBordered target:nil action:nil ] autorelease ];
   2  

posted by Face Saturn on Wed 8 Dec 2010 at 06:09

結末に驚いたのでメモ。

XcodeでBuild & Analyzeすると、下記のようなメッセージが出て困っていました。UILabelのインスタンスを返すような関数なのですが、ちゃんとautoreleaseして返しているのにも関わらず、です。

Object with +0 retain counts returned to caller where a +1 (owning) retaincount is expected

メモリ管理周りをググったり、stackoverflowをうろつくなりして色々調べること数時間、原因を突き止めました:

Object with +0 retain counts returned to caller where a +1 (owning) retaincount is expected - Stack Overflow
http://stackoverflow.com/questions/3553401/object-with-0-retain-counts-returned-to-caller-where-a-1-owning-retaincount-i

結局、コード自体は間違っていなくて、「関数名が良くない」ということでした。AppleのMemory Management Programming Guideには下記のような記述があります:

You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy).

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW1

[意訳] Objectを作成する際にはalloc, new, copyなどで始まる関数名を使う(例、alloc, newObject, mutableCopy)

コード内の関数名を書き換えて、解決!
(newで始まるだけではダメなのですね…)

   1  //NG
   2  (UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor;
   3  
   4  //OK
   5  (UILabel *)createLabelWithPrimaryColor:(UIColor *)primaryColor;

posted by Png satoko on Wed 8 Dec 2010 at 00:21
Contents
moreViewController へ戻る tabBarItem
[Xcode] 関数名が良くないという結末。Build & Analyzeのメッセージ:Object with +0 retain counts returned to caller where a +1 (owning) retaincount is expected
Comments
瀧内元気: MacOS版は以下にあります * [genki/ViMouse](https://githu... '23-1
KingofSmack: Here also good reads for this mobile applicatio... '14-5
Spencer: You don't have to re-compile it, this version w... '14-4
staiano: Any chance we can get a recompile for 10.9? '14-1
dsjf: https://gist.github.com/6bf1bf2c3cbb5eb6e7a7 これ... '13-1
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ