How to scroll a tableViewController's view with only static cells inside? - ios

I have a tableViewController which stores a form for the user to input their information. This form is grouped by a couple of static cells instead of dynamic cells. So it doesn't access the delegate method cellForRowAtIndexPath. Also, I have controlled that user can add some of the attachment and keep stacking. These attachments are stored in a single UIView each. The problem is, when more than 6 attachments were added, the attachment view starts to go out of the screen height. How can I make this tableViewController scrollable?
Please tell me if you need me to show any code.

You don't need to set it scrollable.And you should add these views to table footer view and increase its height at the same time.By this,table view will be able to scroll once its height is bigger than that of frame.

Related

How to make the cells inside of a tableview begin lower down?

I have a tableview. Right now the first cell will begin right at the top of the tableview, but I want it to start some number below the top of the tableview so that I can addSubview() in that spot without covering content in the first cell.
Below you can see what I want to achieve.
The rectangle in the center represents the cells, the line at the top represents the top most of the tableview.
Short answer: You don't. The contents of a table view belong to the table view. You should not try to add subviews to a table view.
As #rickramirr says, you either need to position your table view lower on the screen, or use a header view that contains the contents you want.
(If you decide to position your table view lower down, need to either not manage your table view with a UITableViewController, or have a UITableViewController as a child view controller of the screen's main view controller. A UITableViewController is kind of dumb, and only knows how to manage a table view and nothing else.)
I think that maybe you should add a custom header to your table view or put another view above your table view. Here is Apple docs to customize your header: https://developer.apple.com/documentation/uikit/views_and_controls/table_views/adding_headers_and_footers_to_table_sections
All the views that you want to insert between one tableView cell and another must extend UITableViewCells too. You can create custom cells by defining a new xib file containing a UITableViewCell, whose content could be whatever view you want. Then, you must create a swift file that extends UITableViewCell associated with the xib file. Finally you need to record that cell into the table, either programmatically or by manually inserting it into the storyboard within the table. At that point you will decide its position using the UITableViewDelegate "cellForRowAt" method.

How to change the position of the last UItableview cell in Swift

I am loading different components in the tableview. Each component is having different types of data such as video, image, quick reply and other component.
I am able to load all the data and added to the table view and table view height is adjusted based on the data response.
Now my requirement would be one specific component is displayed at the bottom of the screen always. How do I change the Y position of the particular component?
The problem which I am facing now, not able to change the position of that component.
You can use another UIView fixed at the bottom of the screen below your tableView. You can put that component in that UIView. This way it will be fixed at the bottom.
Another option is using a TableViewController instead of a TableView. That way you can have static cells. You can set the last cell at the bottom however you like. It never changes.

How to achieve a (almost) full view uitableview that can scroll past the last cell and show further elements in iOS

I have attached the below image because it describes my problem better than words:
So basically, I need the Title/Subtitles part at the top to always be static, after that a dynamic UITableView which will have a lot of cells (mostly will fill the rest of the screen), and then after that a few additional elements such as a Map View and etc.
I'm using storyboards/xibs for this so it was also an issue of how to constraint everything in the designer properly. Would a stack or scroll view be appropriate for this?
I think you can take two paths to achieve this.
The first is to create a custom cell containing the map and another containing the "Paragraph of text" thing.
Then you only need to push the cells at the end of the original data source.
Keep in mind that you need to add this cells to the RowsInSection function.
The other way is add a custom footer view to the tableView.
You can create a custom UIView containing the map an other info and then tell the table to take the custom view as footer:
tableView.tableFooterView = customView

how to increase the height of scroll viewheight dynamically in swift 3?

How can i set the constraints that here two table views are using so that both are dynamical and i need to change the height of scroll view so that both table views and it needs to fit the whole screen and my layout will be as shown below in the image
why you are using tableview in scrollview ? It is not good approach to use scrollable entity into scrollview! You can take one tableview and can create multiple cell for every type of your content like payment view, cart view etc. You can use multiple section also as per requirement. For example, your Table details should be your first section, that can contain multiple rows.
By this way your height will be automatically managed by tableview.

What is good practice for code to dynamically add content to View Controller?

I essentially want to have the following scenario.
Very simply, each entry contains a number label, two header labels and two text fields.
Being new to iOS development, I'm not sure of an intelligent, simple way to do this. What is the best way to go about doing this?
This is a great case for using a UITableView. Create a table and a cell prototype that has all the elements that you need (a number, fields for name and age, etc). Create also a different cell prototype for "add more". That would be the last cell in your table. Increment the number of cells when a new record gets added.
There are multiple tutorials online for UITableView. What you want to look for is how to set up and use 2 different cell types. See, for example, this SO question.
If you go with a table view as opposed to just adding some subviews, you get some useful features for free:
scrolling, if you have a lot of records
animated insertion of rows
support for deleting rows/records
easy customization of your list of records: headers, footers, sections.
You can do this manually - there is no problem. Create UITextField, UILabel etc objects in the code, configure them to your liking and add them using
[view addSubview: ]
method
I would:
Create a scroll view - UIScrollView, set the size of this scroll to the size of your main view and add this scroll view to your main view.
Create a content view - UIView, set the width of this content view to the with your the scroll view. But the height should be 0. Set the scroll view in step one's setContentSize: to content view's size. Add this content view as a subview of the scroll view.
Create an iVar to keep track of how many buttons set has been used.
Now every time the + button tapped, create buttons, labels, etc., use the iVar in 3 to calculate and adjust the frame for each buttons, labels, etc.
Adjust the content View's frame to make room for the new set of buttons, labels, etc. Update the scroll view's contentSize: to the content view's frame size.
Add those buttons, labels, etc. in step 4 to content View as subviews.
Case A:
If you are going to add limited number of this type of view
Create one viewController, add textField, label etc to view of this view controller.
Create new instance of this viewController when user clicks add button then use addSubview by refering previously added view's y position
Case B : If number is not limited you will need scroll, then tableView is best option
You will need to create custom cell with your labels and textfield
OR
you can do same using prototype cell if you are using storyboard.
When user will click add button do this
//Update your datasoure for new cell
[tableView insertRowsAtIndexPaths:paths
withRowAnimation:UITableViewRowAnimationTop];
You can create add more view and set it as table footer as it will always stay at bottom, like this
table.tableFooterView = assignYourAddMoreViewHere;

Resources