投稿

7月, 2013の投稿を表示しています

クラッシュ時のスタックトレース取得方法

iOS開発において、クラッシュした場所の検討がつかない場合がありました。 いろいろ調べてみると、NSSetUncaughtExceptionHandlerにハンドラ関数のポインタを渡すと、クラッシュ時のスタックトレースが取得できるようです。 以下のコードはその実装例。 @implementation AppDelegate void exceptionHandler(NSException *exception) { NSLog(@"Exception: %@", exception); NSLog(@"Stack Trace: %@", [exception callStackSymbols]); } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSSetUncaughtExceptionHandler(&exceptionHandler); return YES; } @end 以下のコードで無理やりExceptionを発生してみました。 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSSetUncaughtExceptionHandler(&exceptionHandler); //無理やりEcxeptionを発生させる。 NSArray *array = [NSArray array]; [array objectAtIndex:1]; return YES; } 出力結果は以下。 2013-07-15 19:21:45.415 ExceptionSample[27437:c07] Exception: *** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds for empty array

UITableViewCell の アニメーション

イメージ
どうやら、UITableViewCellを追加、削除、refreshするときのアニメーションがデフォルトで用意されている模様。 指定出来るアニメーションは以下の通り。 typedef NS_ENUM(NSInteger, UITableViewRowAnimation) { UITableViewRowAnimationFade, UITableViewRowAnimationRight, UITableViewRowAnimationLeft, UITableViewRowAnimationTop, UITableViewRowAnimationBottom, UITableViewRowAnimationNone, UITableViewRowAnimationMiddle, UITableViewRowAnimationAutomatic = 100 }; (例) リロードする場合は、UITableViewControllerのサブクラス内で、 - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation; を以下の様に使用すればOK。 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; 復習も兼ねて、全てのAnimationを確認するためのサンプルコードを作成した。 サンプルコード https://github.com/AlginPlus/TableCellAnimationSample