开发者

Is the method addSubview of NSView inherently slow? (Cocoa OSX)

I am trying to speed my gui that loads very slow slow when I am loading a large project (the gui is a representation of groups and sub groups and is made up of 开发者_开发技巧many views). During this process I was looking at how long certain code segments take to execute and I have found that a call to addsubview is taking between 10 and 20 milliseconds most of the time. The subview I was looking at is a disclosure button. I am wondering if this method is just inherently slow or is their some other factor at work here? Is the time it takes to add the subview dependent on the complexity of the subview or is that not a factor? Also, is there some other method that can be used to add a subview that might be faster?


You could try -setSubviews: which takes an array of subviews. This may be faster then calling -addSubview: multiple times yourself.

Otherwise, -addSubview: and -addSubview:positioned:relativeTo: are the only other methods for inserting subviews.

I'm curious, though, why is 10 - 20 ms to slow for a single subview? How many subviews are you trying to add?

It is possible there is an alternative design using NSCell's that may be faster, but without know more details about what you are trying to accomplish, it is difficult to know.


Rearranging the view hierarchy isn't something you'd typically do very often. Instead of adding and removing subviews, you could hide and unhide them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜