简体   繁体   English

iPhone Xcode代码与界面生成器

[英]iPhone xcode code vs interface builder

I've been using Xcode for a while and had a brief look at the interface builder when I first started but then went straight on to coding everything. 我已经使用Xcode一段时间了,当我第一次开始时简要地看了一下界面生成器,然后又直接编写所有东西。

So far it's working OK but I just wondered if I'm missing something by not using the IB. 到目前为止,它工作正常,但我只是想知道是否通过不使用IB丢失了某些东西。

Is there any advantage to using the IB at all? 完全可以使用IB吗? I've even coded subviews and stuff without using the IB but I can't help thinking that it might be more advantageous to use it? 我什至没有使用IB就编写了子视图和内容,但我不禁想到使用它可能更有利?

If not I'll keep on doing what I'm doing as it's working for me up to now :D 如果没有的话,我会继续做我正在做的事情,因为它对我来说到目前为止:D

Thanks 谢谢

If constructing everything in code is working for you, then great. 如果用代码构造一切都对您有用,那就太好了。 Personally if it can be done in IB it's done in IB. 就个人而言,如果可以在IB中完成,那就在IB中完成。

I'd be surprised if there's a best practice for this; 如果有最佳实践,我会感到惊讶。 everyone will have their opinion and preference. 每个人都会有自己的意见和偏好。

I like to do UI related work in IB - if i'm dealing with presentational concerns I like to be in an environment that offers immediate visual feedback. 我喜欢在IB中进行与UI相关的工作-如果我要处理呈现方面的问题,我希望处于可以提供即时视觉反馈的环境中。 It also cuts down the amount of boiler-plate code that you would have if constructing everything programmatically. 如果以编程方式构造所有内容,它还可以减少样板代码的数量。

That said you can't do everything in IB. 也就是说,您无法在IB中做所有事情 There are times you'll fall back on programatically constructing or laying out a view. 有时您会退而求其次以编程方式构造或布置视图。

A little knowledge of both approaches goes a long way... 对这两种方法的一点了解将大有帮助...

New projects always start off simple so people tend to gravitate toward IB naturally. 新项目总是从简单开始,所以人们倾向于自然而然地倾向于IB。 Personally I've found that as a view gets more dynamic and complex (and they always do), it makes sense to code it. 我个人发现,随着视图变得更加动态和复杂(它们总是如此),对它进行编码是有意义的。

YMMV. 因人而异。

possible duplicate of: iphone app best practice - is using the IB a better way to design your app, or writing UI code on your own better? 可能重复的项目: iphone应用最佳实践-使用IB是设计应用的更好方法,还是更好地自行编写UI代码?

at the end of the day its whatever you feel more comfortable doing. 在一天结束时,您会觉得更舒服。 IB is horrible in my opinion, programming takes more effort - more thought. 在我看来,IB太可怕了,编程需要更多的精力-需要更多的思考。 :) :)

I usually use IB, get immediate visual feedback and make the layout looks exactly easier. 我通常使用IB,立即获得视觉反馈,并使布局看起来更容易。 Only in one case that I have to give up with IB is performance with UITableView scrolling. 只有在我不得不放弃IB的情况下,UITableView滚动才能实现性能。 In this case, the best solution I can find is to write code to draw everything in the cell using code. 在这种情况下,我能找到的最佳解决方案是编写代码以使用代码绘制单元格中的所有内容。 This makes the performance much better. 这样可以使性能更好。

Generally, I recommend to use IB until you have some specific requirements like performance or you need to have really much control over the view 通常,我建议您使用IB,直到您对性能有一些特定要求,或者需要对视图进行真正的控制

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM