Using UIScrollView to scroll both TableView and Main Stack - swift

hope everyone is having a great day.
In my ProfileViewController i have 3 views, one that holds the profile information (like photo, full name), then another that has a button, and the last that holds a tableView. All these are in a Main Stack. How can i implement a UIScrollView , that scrolls everything simultaneously ?
I have searched around but could not find something that would work for me.

I think you are in wrong direction!!
What you need to do is
Remove Main(StackView) and add one Single UITableView Or UICollectionView
Create Two different Cell(UICollectionViewCell or UITableViewCell) one for Profile Header and another for podcast and register it with table or collection view
in delegate return 2 for numberOfSection(_:) method and in dequeueReuseableCell method check section and return appropriate cell.

Related

Search bar displaying beneath table - swift storyboard

Seems like a pretty basic issue, but I have a tableViewController and at the top of the screen I've got a collection, beneath this I want to include a Search Bar. But for some reason it won't let me place this above the Table View Cell. It will let me add it into the collection view bizarrely but it goes behind the cells.
Is this a limitation caused by the fact I've included a Collection at the top of the screen? Is there only space for one element above a table on a tableViewController? Is there a workaround whilst still using a tableViewController?
Likely a noob question, but I'm still v noob
Is there only space for one element above a table on a
tableViewController?
Correct.
You get one header view area, and one footer view area for the tableViewController as a whole. (plus extras for the sections)
If you want a quick solution for a simple table then the tableViewController saves you about 60 seconds. - but if you want to do something more complex now or later, then you may want to consider using a regular UIViewController, dropping a UITableView into it and applying constraints as needed.
You would also need to remember to set the tableView dataSource and delegate up and comply to their protocols - or you go the diffableDataSource route.
Thanks #agentoverflow I couldn't find any documentation that explained the limitations of a UITableViewController.
Came up with my own solution. Put a view into the header area and put my collectionView and searchBar into that. Hooked the code up for both elements and both are working as expected.

Newbie TableView challenges

I am building an app that requires a tableview control so that users can select multiple rows and act upon them in some way. I find it easy to load my data and display it using the UITableViewController but it seems when I do it this way I am unable to place any other controls on the page, such as a toolbar to give the user some actions to perform on the selected rows. I can place a toolbar control on the form in the storyboard, but it doesn't render in the emulator.
Using a UIViewController and placing a TableView on it seems to come with its own set of confusing challenges (that will make total sense once I conquer them).
Is there any advice for a smooth way of getting a table view with toolbar controls? Thanks!
don't use a TableViewController. Use a Standard ViewController, then add a UITableView to it, and adjust the size. This way you will be able to do whatever else you want on that view without limiting yourself to the tableView only functionality.
When you do this make sure you add the datasource and delegate to the connected table. Then add cellForRowAtIndex, number of sections, number of rows, and whatever other delegate methods you need for your table.
Good luck
Is there any advice for a smooth way of getting a table view with toolbar controls?
Yes there are few ways to accomplish this, one way would be adding a footerview to your tableviewcontroller check these
http://developer.apple.com/
UIButtons on tableFooterView not responding to events
Easier way to add this is using storyboard.
Just drag and drop a view in to your tableviewcontroller, then you can adjust the views size and put anything from objects menu to inside of the view.
Now the problem with that is view will not be stable position at the bottom of the page like a tabbar. Lets say you have only 1 row in your tableview, footer view will go up just below that 1 row, lets say you have hundreds of items in your tableview toolbar will be at the bottom of the rows.
The other solutions for your problem would be either create a custom view and adding it to current view or window (this is little bit adbance),but if you want this just google it.
Or just as you said, create a viewcontroller and put a uitableview inside. Dont forget to add <UITableViewDelegate,UITableViewDataSource> to your .h file and then you can call UItableview delegate methods.\
Good Luck.

UIScrollViews and Dynamically Creating Pages

I want to be able to dynamically populate UIScrollView. Like how it is done for row views in UITableView. I have a class that takes in some parameters and creates the respective view when it scrolls. Currently I have 8 views.
These 8 views have different background image, image and label according to the page number it is currently in. However the basic skeleton for this view is the same. What i am doing right now is in ViewDidLoad I am creating 8 views and add them as subviews and scroll over.
I don't want to do this. I want to create three views and the rest i want to populate when the user scrolls a page and then a page etc. How do i do this? ANy pointers/tutorial?
First of all you calculate the ContentSize for the scrollview (when you want to use the iPad in landscapemode with 8 pages then the width should be 1024*8 = 8192px and the height 768px).
Then you should implement the UIScrollView Delegate method:
scrollViewDidEndDecelerating:
In this Method you check on which page you currently are with the contentOffset property of the scrollview and start updating your left and right hidden views..
Hope this helps you a bit.
Check the two most recent WWDC videos for two excellent sessions regarding expert use of UIScrollViews. Additionally you can review a brief tutorial here, written by the well known cocoa expert, Matt Gallagher.

iPhone: can I add Tableview in cell of another tableview?

I have to create a UITableView. Suppose there are 2 table views TableView1 and TableView2. TableView2 will contain suppose 2 text boxes. And I have to add TableView2 in one cell of TableView1. Finally I have to access the values of text box from the inner TableView2 in the TableView1.
I am new to iPhone development. In short I have to add a tableview to the cell of another tableview. I don't know whether this is possible. If it is, would someone please provide me some link or code to do it.
This is not look good design. You can also use two text field in same cell and make it more in height also make a horizontal separator. also if you have only two textfields then make them global and declared as property.And add in a particular cell.
Read some tutorial for making custom cells and give some time to learning these tutorials.
See this link and by googling you can easily find more on this topic.
Yes, you can do. Of course, It is not good practice to do like this. Still you want then here is the trick to do that.
Create Two ViewController and inherit them using UITableviewController say ViewController1 and ViewController2.
Now in cell of Tableview1 add ViewController2 object. So Tableview2 would in Tableview1's cell. Now you need to handle inner tableview delegate & Datasource in Viewcontroller2. So you don't need to do lots of if.. else in same view controller.
Now you can take two textfield in Viewcontroller2.h file and assign cell's textField to that in cellForrowIndexPath method. So you can access both the textfield any time you want.
I know my answer is bit confusing but ask me any question if you have.

Is it possible to put one UITableView over another UITableView in InterfaceBuilder?

I know I can use codes to add UITableView one by one.
[self.view addSubview:tableview1];//
[self.view addSubview:tableview2];//
I hope to do the same thing in InterfaceBuilder, when I drag one UITableView onto another one, the new one always pushes the old one to the bottom, rather than just stays over the old one of UITableView.
Welcome any comment
Thanks
If you have a parent view that will contain your tableviews then you shouldn't have any problem. If you're trying to place them directly in a window then I could see a problem. If things aren't lining up the way you want you can always change their position via the Size Inspector or by nudging them with the arrow keys (shift-arrow key moves in 10 pixel increments).
Why anyone would want a tableview on top of another tableview escapes me.
Your parent view should be a subclass of uiviewcontroller and your xib should have the root view as a uiview and not uitableview.
I used two overlapping table views to show two different contents on the same view, which could be toggles using a segment switch. Apparently my client requirements were vague enough that I couldn't just filter out data like how the phone app displays all calls/missed calls list.