3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Superviewはどこまでもチェーンできるのだろうか

3
Last updated at Posted at 2014-06-05

あるビューを上にたどっていくときに

aView.superview.superview.superview.superview.superview  ...

みたいなひどいコードを書いて落ちたりしないのかしら、という疑問。aViewがscrollviewの中に入っていて、そのscrollviewまで何個たどればいいのかわからない、とか。

で、まあこんなコードを書いてみて実行する

    int i=0;
    NSView *v = _myView.superview;

    do {
        NSLog(@"%@", [v description]);
        v = [v superview];
    } while (i++<10);

2014-06-05 16:01:42.106 Superview[6135:303]
2014-06-05 16:01:42.107 Superview[6135:303]
2014-06-05 16:01:42.107 Superview[6135:303]
2014-06-05 16:01:42.107 Superview[6135:303]
2014-06-05 16:01:42.107 Superview[6135:303] (null)
2014-06-05 16:01:42.107 Superview[6135:303] (null)
2014-06-05 16:01:42.107 Superview[6135:303] (null)
2014-06-05 16:01:42.108 Superview[6135:303] (null)
2014-06-05 16:01:42.108 Superview[6135:303] (null)
2014-06-05 16:01:42.108 Superview[6135:303] (null)
2014-06-05 16:01:42.108 Superview[6135:303] (null)

nilに対する superviewメソッドの呼び出しでは特にエラーになることはないようだ。最初に書いたひどいコードもとくに問題はないみたい。

objective-cのこのへんがよく分からない。呼び出してもnilが返るばかりで特にエラーにならなかったり、割と厳密に「そんなセレクターねえよ」と怒られたり、その辺の基準が。

3
3
3

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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?