LoginSignup
0
0

More than 1 year has passed since last update.

いにしえのアプリ、iOS15〜対応時のUITableViewの仕様変更で詰んだ

Last updated at Posted at 2023-03-06

未だSwiftなんで言葉もなかった時代にobjective-cで作られた、10年以上保守しているiOSアプリケーションでiOS15の対応に迫られた際、日本語での記事が見つからなかったので投稿。

この記事対象の人

  • 未だにobjective-cで頑張ってる
  • とりあえずサクッと対応させたい

UITableViewCellのCellが、意図しないCellで返ってくる問題

UITableViewCellを押すと、そのCell上にポップアップのようなUIを表示させ、Cellの値を更新できるUIがあった。しかし、iOS15〜から、ポップアップUIからCellの値を続けて更新する際に、表示させているポップアップの位置が他のCellの位置にずれる問題が発生していた。(伝わるかな…)

どうやら、iOS15から、isPrefetchingEnabledがデフォルトでTrueになったとのこと。

これがTrueになってると、cellForRowAtIndexPathのデリゲートメソッドが、Cellが表示される前に呼ばれて、いにしえのコードのままだと正しいCellを取得できなくなってしまったっぽい。

サクッと対応させたいので、こいつをOFFにしちゃおう。

AppDelegate.m の、didFinishLaunchingWithOptions 内に書きましょ。

UITableViewCellの挙動をiOS14以前に戻す

[[UITableView appearance] setPrefetchingEnabled:false];

その他iOS15対応(objective-c)

UITableViewにHeader設定した際の、Cellの変な隙間対応

AppDelegate.m
[UITableView appearance].sectionHeaderTopPadding = 0.0;

NavigationBarの背景色対応

AppDelegate.m
UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
[navBarAppearance configureWithOpaqueBackground];
navBarAppearance.backgroundColor = [UIColor whiteColor];
navBarAppearance.titleTextAttributes = @{NSForegroundColorAttributeName : UIColor.blackColor};
[UINavigationBar appearance].standardAppearance = navBarAppearance;
[UINavigationBar appearance].scrollEdgeAppearance = navBarAppearance;

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0