Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
290 views
in Technique[技术] by (71.8m points)

ios - UIView outside of a View Controller in a Storyboard

I'm stuck with a question I can't find an answer to in the official documentation, on Stackoverflow or on Google.

I'm an experienced iOS developer but new to Storyboards. I'd like to instantiate a view on the current viewcontroller, a view that, in a NIB, I would draw outside the viewController and attach an outlet to to refer to it in code and call something like addSubview: or so. It's useful to draw an overlay or, in my current case, a callout view for use in a MapView delegate. But I can't figure out how I can do this in a Storyboard.

I can't seem to have a view outside of a viewcontroller, and views inside the viewcontroller either have to be subviews of the controller's view or don't be visible in Interface Builder at all (which is okay when you drag a view composed outside, in a traditional NIB, but quite a problem if you need to tweak even the least detail of it).

Any hint on what to do or where to look? Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It appears there is no way to do it. See Jason's comment and this question addressing the same problem, though in a different context.

However, I realised earlier when thinking about the implications of my problem — as I began to explain in my previous comment before deciding it would be worth a full answer — it makes sense to separate the design of a custom view from the design of an application flow. So the fact that it's not possible to design custom views in Storyboards may very well be... by design.

A custom view (which is a reusable component) is very different from a view controller (which represents a scene in your application storyboard). It's the same as a character and a scene, in a movie. You don't want to design your character in your scene, even if you happen to use that character in only one scene. It's fortuitous if you use it in only one scene, but not essential. So it has to be separate.

The fact that you want to use Interface Builder to design your custom view is only an implementation detail that should be encapsulated in your class. The application storyboard has no need of knowing, even less managing, how you deal with the particular implementation of your reusable view.

Hmm, I wish I had more of this brand of interrogation :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...