I am new to IOS, I want three table views in one view controller. when I scroll in horizontal it will move to table 2 and table 3. please help me in coding. how doing it.
Put horizontal scroll view with content offset width equal to 3 tables width then add uitableviews to that scroll view with proper x origin. Obviously it would be better to use NSLayoutConstraints for that, but the first way is o.k. for you I guess.
Related
I am trying to create the following layout with a NSTableView:
A big banner per section on the side and regular text content rows on the right side.
The Image on the left side is the problem. It should behave like a floating section when scrolling (stay below the section header). It seems impossible to have the view part of the NSTableView as each column of a row needs to have the same height.
I already tried a lot of things, but I need some input which is the right direction.
What I tried:
Add the image view as a floating view into the NSScrollView? That seems like a good approach, but it doesn't stick on top while scrolling and the (re)positioning within the table is... tricky. Any hints here?
Add the view into the section header and disable clipping somehow (to make them larger than the section)? Couldn't make that work.
Having a table with NSStackViews per row that host itself tables - that did work, but: Independent selections per table is not what I want.
Ok, I finally found a solution.
The view is added to the floating view container of the NSScrollView that holds the NSTableView. I use the bounds of the row views and translate that to coordinates of the floating view container.
I also modified the selection drawing to make it look good and recalculate the coordinates on animations.
I am using view based NStableview and I am using table header for providing space between top of scroll view and first row of my TableView. I want this space to scroll up when user scrolls tableview, but the header is floating and is not scrolling up. It just sticks there on the top.
I need to provide a gap between top of scroll view and first cell of header view. I can think of other solution like creating a different cell for first row, but this solution creates whole bunch of bugs with indexes of table and data. So I decided to use table header for providing the space between top of scroll view and first row of table view.
Is there any solution for this other than using header for table? If no can I disable the floating behaviour of header view?
To disable floating just set floatsGroupRows = NO ?!
Maybe the contentInsets property of NSScrollView is what you look for.
You can define a top inset. (100 in my example)
Code (same for Swift and Objective-C):
self.scrollView.contentInsets = NSEdgeInsetsMake(100, 0, 0, 0);
I know this question has been answered before, many times, but my use case seems to be just different enough from all of them that I can't quite figure it out.
My Problem
I have a scroll view that is not the same size as its superview. The scroll view has 1 subview that is the same size as it, but it needs to be able to be pinch-zoomed.
Attempted Tutorials:
(1) - Apple's Technical Note - This is done only with code and the examples show only full screen scroll views.
(2) - Natasha The Robot's Article - This was a really well written article but I could not get it to work for me. I think it's due to the fact that her scroll view is full screen.
(3) - Happy Coding Blog Article - Another full screen scroll view
... and lots other tutorials that were very similar to these
My requirements
My scroll view needs to be full width
My scroll view needs to be 40pt from the top and have a 1:1 aspect ratio
My scroll view needs to have one subview that is the exact same size of it but can be pinch-zoomed (aka content size = scroll view size)
I don't think that the size of the scroll view should impact anything, but it appears to.
What I have tried
As all the tutorials above recommended, I have only a single subview of the scroll view and have aptly named it "Content View".
View Controller
|-View
|-ScrollView
|-ContentView
|-ZoomableView
Here is a picture of my constraints:
As you can see, I have an equal width set up from the "Grid" (Zoomable view) to the view controller's view. I've also tried adding an equal width of the content view and the VC's view.
My question
I know I can get this to work with an explicit width and height, but I know I should be able to get it by setting the width equal to the view's width and height equal to the view's width as well (AKA 1:1 aspect ratio). How can I achieve this?
I think I ran into the same problem in the past. What I end up doing was adding a "container" view and use it to set up my width and height equality constraints instead of the view controller's view.
This setup will produce what you want I think: a scrollview with 1 subview that can be pinch-zoomed in the view controller's view (grey in the screenshot) but with a top margin of 40pt.
Without using code, I'm basically trying to achieve the "Desired outcome" in this picture:
I want the constraint on the "Hello!" label to shrink its length when the screen height is shorter.
As you can see in "Actual result", the Button in the bottom is off the screen. I want the image view to have fixed width and height.
I know I can create IBOutlets for constraints and doing it by code like this kind of posts suggest (autolayout - make height of view relative to half superview height), but I'm trying to avoid using code as much as possible.
Side question: If there's no way to do this in IB, what are the best ways to do this in code?
Thanks for the help!
Yes. The easiest way to have this kind of "split height" constraint is to put a "header" view between your image view and the top of the screen, and embed your "Hello" label inside this new header view. Then add a constraint to keep the "Hello" label vertically centered inside the header view.
To keep the header view the right size, add constraints to keep the top of the header view pinned to the top of the screen, and the bottom of the header view to the top of the image view.
Then you'll just add constraints to keep the button and image view pinned to the bottom of the screen. (Or, see comment from Sulthan, below.)
In Xcode 5.1 (in beta), there is UI to make more general constraints, including the ones you want, but you have to do it like this or in code in earlier versions.
I'm trying to add 3 UItableviews to a viewcontroller view using IB and adding auto layout constraints to achieve the following conditions:
space between tableviews and borders = 20
space between tableviews = 20
Equal tableviews widths
when I run the app on the simulator, I get a strange behavior. The tableviews seem to be positioned correctly, behave as expected during rotations, but the content of one of them is always shifted down...
it looks like a space above the header that I can't explain and remove...
Any ideas ?
Thx.
H.
Add the top constraint to the first table view and bottom constraint to last tableview in the view controller and in the middle tableview assign top and bottom constraint as vertical spacing between the table views and height as less priority. It may work.