Editing a UITableView that contains dynamic data in each row? - ios

I have a UITableView that is separated into sections with one row each. Each row contains a horizontally scrolled UICollectionView. I am wanting to add the functionality for editing this list when I tap a general edit button in the top of my Navigation Controller. The issue that I'm thinking of is that all of the content will still move around and be active (tapping on a cell in the CollectionView will open a different page). I am wanting the edit mode to either disable that functionality or slide all of the content over simultaneously and have an edit button next to them all. When this edit button is pressed it will take the user to an edit page specific to that rows content (so no delete functionality here). Another reason why I am having a difficult time is that all of the content in the table will be loaded via data so I don't want to reload any of it.
Bottom line is that I need to select a single row and it must be done via a button that slides in or altering the functionality of the content there to act as a button. I cannot reload the data in the rows, though because it is loaded via internet data.

Related

Should I choose ViewController or TableViewController?

New to Swift. I am trying to write a recipe-sharing app for fun. One of the features is to let users create a new recipe. On this page, users should be able to give an intro to the recipe to be created, upload an image THEN add a LIST of ingredients dynamically (as we have no idea how many ingredients in total beforehand).
I have created a UIViewController, which includes a UIViewTable, an image view and a "add another ingredient" button. I have created a class for the ingredient. And when the "add" button is pressed, a new "Ingredient" cell will be added to the table. However, I found that adjusting the UIViewTable height dynamically is quite hard.
I want my table to adjust its height according to the number of cells (rows). I haven't found much useful info online.
Or maybe I should've not even used this structure. Instead, just use UITableController (The entire page is a table)? But I got confused that some of the elements (image view, submit a recipe button, recipe-intro textfield etc) will be only created once. Why do I bother making them as prototype cells and add them to my view programmatically?
Thanks in advance!
First of all, welcome to Swift!
You put a few questions together, I will try to answer them one by one. Let's start with the simple stuff.
Don't try to change the height of UITableView based on the number of items. If you want to achieve similar functionality, take a look at UIStackView. Set fixed size for the tableView, ideally with constraints using auto layout.
UITableView is supposed to fill specified space and scroll items inside or show cell on top if there are not enough cells to cover all space.
UITableView is highly optimized to scroll over huge amount of cells as the cells are reused on the background. If you are new to the iOS world, take a look at this function https://developer.apple.com/documentation/uikit/uitableviewcell/1623223-prepareforreuse it can save you hours of debugging (I have been there)
UITableView vs UITableController
UITableController can save you a few lines of code, but using UITableView inside of UIViewController can give you more freedom and save you refactoring if your app is likely to change in the future. There is no specific advantage of UITableController
If you want to provide the extra elements (image view, submit button, text field etc), you can use several methods and this is where the UIViewController with your own UITableView comes in handy.
You can put some buttons, like a plus icon or "Done" button into the navigation bar, as the native Calendar app does.
You can put the static content (intro text field, image view) above the table view (visible always). Use constraints to place the static content on the viewController.view and constraint the table view under your static content. The table view will take less space on the view keeping the space for your content.
Insert your static content as a table view header (will scroll out with the content). Search "HeaderView" here on stack overflow to see how to achieve that.
Place your content over the tableView. If your button is small (rounded), you can place it over the tableView, eg. Twitter uses this for a new tween button.
Hope this answer your questions. Cheers!

First button of UITableView as Search as well as Add textfield

If you see the screenshot below, its a view from iOS Files app which lets you select tags for a file.
I want to make a similar Tableview which lets user either select existing items or add new items. But I also want the add textfield to be a search field. That is, when the user starts typing there, he also gets search results from the existing items.
The way I am planning to implement this is...
Two table views.
One has a static cell to 'Add' and is not vertically scrollable.
Right underneath is the second table view with existing itmes, which is vertically scrollable.
when the user taps and starts typing in the textfield, there is a search side by side, in the second table view and the user can select an item from it as well.
When there are no matching results, an add button is highlighted and the user can add a new entry.
I want to know what is the best way one can implement such behaviour?
Also,
(In terms of UI Design)
Should one make use of the UISearchBar instead of a textfield?
Or, is it better to simply use the UISearchController?

Change tableview cell index

I'm building an app that pulls data from internet (events) then it displays all the events in a tableview (different sections based on dates).
If user clicks on any event it expands, and then they can favourite the event or event host. How i can reorder my table to show those favourited events first. Because i didn't build my app with any in app "data model", what i mean is that all the data displayed in the tableview (ordering) is based on the pull request, what ever comes first is displayed first.
Are there any way to force some certain cells to top of the section? Manually reorder the cell's in code in my situation?
And one other question? I'm using section headers (dates) , but can i have two headers so it's (Header)date - (subheader)city - (cell)event. Or am i limited to only one section header?

Loading Data in sameTableViewController based on button press Swift

I'm working on a sample iOS app and want to load (in a tableViewController) certain data based on the button the user presses at the top of the view. For example, when the user loads the page it will by default load data from "myPosts" but on the top of the view there will be two buttons "My Posts", "Not My Posts". If they then select the "Not My Posts" button then the tableview cells will be reloaded with the data from "notMyPosts". Anybody know how to do this?
So, the best solution here is to use a Segmented Control. Basically, you will have a controller for each TableView and a controller for the SegmentedControl.
This tutorial and this question gives a basic idea on the segmentedControl and how to set the basic controller for it. You will basically have a Container View with a view for each tableView you want to display and show/hide it based on the selected segment on the SegmentedControl.
This is how your storyboard will look like:
Just use two different datasources for your table, depending on which button the user selects.
So, when the user taps on a button set a variable to keep track of which button they tapped, and then reload your tableview.

News Feed drop-down filter menu in Facebook iOS App

The Problem
I am trying to replicate the drop-down style menu in the latest Facebook app.
At the top of the News Feed there is a "Most Recent" row:
Tapping this row expands the view, pushing the News Feed (UITableView) down:
Tapping the down indicator will expand the menu fully.
The Question
How is this menu implemented?
Given the behavior, I assume it is a custom view placed inside the tableHeaderView. But what custom view? A button, another tableview? What about the animation?
You wouldn't be able to do this as a table header. It'd need to be a section of the table that is initially 1 row and becomes multiple rows when you tap on it. Then all you would need to do to get an animation is to reload that section where animated=YES.

Resources