Moving UITableView in xib - ios

I have a simple question for you.
I load images and strings from sqlite3 base. If there is no image, i want to move up my table view.
How can I realize it? I tried to change frame.origin.x, but it doesn't work.
Link to my project https://github.com/serg1991/diplom

Can you be more specific about the exact position of your problem in your project? It's kinda big.
Also, if you need to move up your view, what you want to modify is frame.origin.y.
Otherwise, make sure you don't change your tableView's frame too early in the view lifecycle. Try doing that in the -viewDidLoad of your controller.

Be sure not to use a TableViewController in storyboard... Use a viewController, and drag a tableview inside (of course now you'll have to manage the delegates your self).
Hop this can help

Related

How to decide what view should be on top in Interface Builder

So i have a problem that i know how to solve but not in ann efficient/fast way. Look at this example that i have right now:
So I had made all the outlets before I decided that I need a background image. You can see that I marked them but they are under the UIImage. I can solve this by first removing the image and dragging all the views to another view controller then adding the UIImage and putting the views back on the ImageView but this is time consuming as I have other view controllers. Is there another way to move views up/down?
Think of the views as being listed in the order they are placed on top of others. You start at the top of the list, adding views, and then add the ones next on the list on top, one a time. That's how I remember the ordering.
As Luk2302 says, you can simply drag your views around inside your storyboard to change their order.
Note that there is also an "arrange" sub-menu in the editor menu for IB. You could select your background image, then pick editor>arrange>send to back to move the background view to the back of the stack of views.
P.S.: Don't call them outlets. They are views. Views can be linked to your code using IBOutlets, but they don't have to be. Plus other non-view objects like constraints can also be linked to your code with IBOutlets
Its simple.what you have to do is simply drag you imageview to the top of the view(then it becomes the first IBOutlet you added). I have added some images, then it will easy to understand.
this is your situation
this is the solution(drag it to the top of the view)
then your other IBOutlets come to the front like this

What is the correct way (or better place) to use topLayoutGuide/bottomLayourGuide in code?

Assume you do not want to use storyboards and instead programmatically create your viewControllers / views and autolayout them by code also. How do you properly make use of topLayoutGuide and bottomLayoutGuide? They are properties of the viewController.
I might be wrong, but I think the proper place to set constraints for autolayout are the relevant views and they usually are not supposed to have references to their viewControllers (again afaik).
Am I mistaken and the coding of constraints should be done in the viewController or if not, how do you get the information down to the views?
Please be patient I am learning ;-)

How could I clone/duplicate some sort of UIView for iOS?

(screenshot below helps explain what I am trying to do)
The idea behind this is that I have a UIView, with various different UI elements inside, for example, let's say I have a UIView, and inside there we have a UILabel.
Now I'm wanting to duplicate the UIView (with the label inside) BUT somehow after that I need to perhaps make a change to the label, e.g. change the text property.
The reason I need something like this is so I can structure the UIView with everything I need in it looking nice, but to actually have different data with different copies of it.
I'm not certain this is the best approach, but it's the only one I could come up with. If anyone has any ideas on how to do this, or any ideas on a better approach I'd really appreciate it. A lot!
I personally think the best answer is to create each view separately and configure it as needed. You can make a method that just configures new UIViews to look the same, and pass each view through it.
However, if you really need to copy a UIView, you can archive it, and then unarchive it:
id copyOfView =
[NSKeyedUnarchiver unarchiveObjectWithData:[NSKeyedArchiver archivedDataWithRootObject:originalView]];
UIView *myView = (UIView *)copyOfView;
[self.view addSubview:myView];
If you have a bunch of these, make sure you're using the Instruments time profiler to check your drawing efficiency.
This is a very natural and useful thing to do. What you're looking for is a container view controller. Put your reusable "cell" into its own view controller and its own nib file. Then, in your parent view controller, use addChildViewController: to add as many of these as you'd like and configure each of them. They can each have their own IBOutlets that you can use to modify the contents.
This is very similar to the pattern used by UITableView and UITableViewCell (it doesn't use "child view controllers" specifically, but it does use this pattern).
For full details, see "Creating Custom Container View Controllers" in the View Controller Programming Guide for iOS.
Note that Storyboard includes a "Container View" as an option in the object templates to make this even easier.
If you want lower-level access, you can also do this by hand using UINib to load the nib file and wire its outlets (and this is how we used to do it before iOS 5), but today I would use child view controllers.
If you have only one label inside it the obvious solution is to have a custom UIView subclass with that label added as a subview. Everytime you need a new view you make an instance of your custom subclass and set the label text. If you have multiple things to set, some of which are common to all your custom subclass views you can use the prototype design pattern, it's pretty straight forward to implement.

Embedding a UIScrollView with a UITableView

So Path uses this type of page where there is a view above their customized looking table that is a background photo, which contains some user info among other things. I'm trying to recreate something very similar to this.
So lets say that I hypothetically wanted to make a view that shows exactly the way the Path app does, but instead of that weird customized version of a table view that they have, there is an actual table. How would I do something like this? The reason why I would need there to be another UIScrollView embedded into the view is because the entire thing needs the capability to scroll. I'm trying to be as detailed as possible, but its a little difficult to explain.
What I'm imagining is going to happen if I just tried it right now, is that I'd embed a UIView above a UITableView within a UIScrollView that's the size of the frame, and when I'd go to scroll, the user would only scroll the UITableView, and not the entire thing at once. Hopefully that helps convey my doubts.
Another possibility is that I'm totally over thinking this, and I can simply just subclass a view in the header of a UITableView and it would stretch the width and height that I'd like. Hopefully this is the way as this would be easy!
Anyways, can anybody weigh in on this?
Path just uses a normal UITableView with UITableViewStyleGrouped.
The custom view at the top is the header of the first section of the table.
They also access the UIScrollViewDelegate method of the UITableView to change the look of the view (I think the image is moved) when the scroll view scrolls.
If you'd like a tableview that only scrolls within a part of the view and other stuff above it then you need to use a UIViewController. Then you can make it conform to UITableViewDelegate and UITableViewDatasource and add a UITableView and make the view controller the datasource and delegate.
Then you can also add a UIScrollView to it as well.

QuickDialog within frame

I'm trying to employ QuickDialog for an iOS 5 iPad app which uses storyboards, but I guess the question would broadly apply to UITableViewController as well.
My understanding is that when I'm initialising the QRootElement, the tableview that QDC creates will replace the view of my class, thus rendering ineffective anything I customise in the IB storyboard. I would like to be able to design the UI in IB, and have the QD table show up as a frame instead of taking over the whole screen.
I think the solution is to have the QuickDialog tableview set up as a subview of my UIView-based class. Is this correct? What would be the best way to achieve this? Would I have to rewrite the root initialiser in my custom view controller that inherits from QDC, or is there a different way, perhaps something like the approach used here?
Thanks!
I would recommend you inherit from the QuickDialogViewController as your main controller. The QDViewController inherits directly from UIViewController (instead of UITableViewController), so it's quite easy to just move the table view around and add controls around it.
If you really want to create everything from Interface Builder, your tableview will have to inherit from QuickdialogTableView, and you'll have to provide the delegate and data source yourself. Look at the QDViewController for that, as you'll have to write pretty much the same code.

Resources