Loading a xib file on several different UITableViewControllers issue - ios

I wonder if any of you guys ever encountered this problem.
I have a xib table cell with UIImage, UILabel(s) and an UIButton. Pretty simple and straight forward.
The thing is, when I use this xib on different UITableViewControllers, the positioning of my elements are not the same. Any ideas?

Well,
Check your springs & struts or restraints to make sure that they are correct.
If still not working and you are using storyboards, give up this xib and arrange the storyboard directly. This will involve copy the UI over for multiple times.
Last resort, manual layout in -[UITableViewCell layoutView].

Related

Is it a good idea to use xib files in storyboard

I have a project which is based on storyboard. The problem is some views are repeated in some view controllers.
I created xib file for these repeated views and then I use don't create theses view again. I just add a uiview and set its class to the custom view I have created.
It work ok as it avoids repeated view changes.
But I don't know if this cause performance or any other problems later.
And I cannot change the whole project to only use with xib files.
one of the clean code goals is to reuse your code. so base on this, xib file is a good solution, but about performance, using interface builder has less performance than implementation through code. if you are concern too much about performance, use the code, if not, your implementation is ok.
If your project has similar kind of design or view then yes using xib with storyboard is good. you can reduce redundancy by taking similar kind of view or Tableview cell or collectionview cell. that will also make your storyboard neat and clean.
you can check this and based on that you can use as per your requirement.
Which is more efficient way? StoryBoard or XIB?

Storyboard of a mockup

I am working on an e-commerce based app, and the designer has passed on the mockup to me. !
This is the mockup the designer has passed.
I am working on storyboard of this mockup and I have managed to get to this level as of now.
There are several views and features which cannot be included in this storyboard now because of the limited space. I know the designer has passed on me the rendered view, which can be seen on scrolling the app.
I wonder which could be the best approach to include all these views in a single storyboard or render them in a single view.
I have looked onto using xib files and calling them from my viewcontroller class, which could be a possible solution. But, I want to know, what could be the best solution?
Best solution is use Storyboard so that you have all screens at one place. But keep one thing in mind that start doing the whole project in XCODE 8 storyboard (Because XCODE 7 and 8 storyboards are not fully compatible with each other). So that you get compatibility with previous iOS versions also (< iOS 10)
Now as far as design is concerned, I would like to suggest you use autolayouts and proportional layout.
your View controller will always have self.view. Start on that view. First add navigation controller (with root view controller as your first prefered view controller on app start) or simply add one toolbar. Then add one UIScrollView to whole remaining space. Then start with your design inside UIScrollView. Don't forget to provide contentSize of UIScrollView.
For any help, feel free to ask.
The best solution would be using a tableView with multiple prototype cells for this kind of problem. Well, going through the concept as mentioned, I could easily scroll in the storyboard and maintain my design as per the mockup.

Custom UIView in Xamarin Storyboard

Does anyone know if we can design our custom UIViews in Xamarin's storyboards ? I would like to use autolayout and size classes for a custom View that I need to develop. I am not much comfortable with Xcode, having been so attached to Xamarin's IB. So I would prefer to design it in Xamarin storyboards than going for XIB files. I know we can prototype UITableViewCells in storyboards, but that is not what I want. I want a standalone custom UIView, with a code-behind class that I can re-use.
I am a bit confused as to what you are asking.
Are you wanting to design XIBs in the Xamarin Designer?
Currently, it is not possible as storyboard's XML and XIB's XML are completely different. But it looks like Xamarin is thinking about supporting it as it is on UserVoice here. So you could vote for it and hope it gets added in.
Another option is to start using Xcode.
I have found out a way. But it is kind of a hack and will increase bundle size and thus a memory-inefficient way. First add a View Controller to the storyboard and give a class name to create a code behind, say "DummyViewController". Then drag a UIView to DummyViewController and in "properties" pane give "class" name as the name of the Custom View as shown in the image.
A code behind for this View will be created in project folder, MyCustomView inheriting from UIView. Now we can design the view from within XS storyboard with AutoLayout and Size Classes without a separate XIB file.
I do not recommend this unless you really want it to be done this way. Hope Xamarin will come up with a solution to design Custom Views from within XS soon.

Why don't my views show up in Storyboards and are greyed out in the left pane?

I am experiencing a weird bug in Storyboards.
I set up a UITableViewController with prototype cells and set some autolayout constraints. Everything fine until here.
Then, I had to move the whole project directory into another folder. This is a normal action I believe that shouldn't lead to any problems since the app and all the files are pretty much self-contained.
However, since I moved the project, the prototype cells in the UITableView are shown empty within my Storyboard, but the subviews are still showing up in the left pane where all the scenes and views are shown... Only that they are greyed out (see the screenshot)... Does anyone know what this means? I also looked into the XML of the Storyboard file, but everything seemed normal to me in there...
Any ideas?
EDIT: Strange thing also is that the IBOutlets from the custom classes still are set and link to the views in the storyboard... but only in the left pane, not in the storyboard itself.
Just found an answer myself, it was because Size Classes were reset after I moved the project...
Greying out views is Xcode's standard behaviour when the views are only set for a specific size class which is currently not selected!
I had set the size classes for my UIViewController to Compact - Any, this is what it looks like in proper state:
The problem occurs when I change the size classes to another one (e.g. Any - Any):
This happened to me because I copy and pasted some of my views from nib into storybaord. Turning size classes off, and turning it back on fixed the issue. This can be done in File inspector, using a checkbox named Use Size Classes

iOS multiple XIB in a View Controller

I have a View Controller that displays 3 custom views. My question is, would it be better to create a XIB for each subview or not?
I have been told that loading a XIB file is really expensive, so it's better to have just one XIB for the View Controller and avoid having XIB for the custom views in that controller. However, in order to avoid that, I have seen the custom views' constraints set by code (as there is no XIB for them and no way to use the IB), which I don't like. That's why I'm wondering if it's fine (both a good practice and efficient) to create a XIB for each subview and set then set the constraints using the IB.
Thanks in advance.
Unless you are planning on destroying views with a large amount of components and rebuilding them serval times a second you should not notice any performance hit. If you do, cache them.
As for best practice (in my option) you don't use XIBs for the efficiency, you mainly use them because they are quicker to build and easier to understand if you need to revisit the view at a later date.
If your going to use AutoLayout in code anyway I would use XIBs where possible as you get the advantages above. The layout engine is usually the expensive part anyway.
Hope this helps.

Resources