Loading Data in sameTableViewController based on button press Swift - ios

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.

Related

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?

Implementing custom callout button for "About"/ "Info"

Im extremely new to iOS and i have a requirement where in table view, each cell displays list of stores near by and also an info button at the end which shows the timings of the stores. Info accessory button like this and my requirement is to display callout alert as below on tap of that button.
Do I need to create custom view of small size and display that view every time when user taps on that? Please advice how to achieve this in Swift.

Can I choose only portion of a row in UITableView to be clickable(selectable) in Swift?

So I have a table in the accordion style. When a row is clicked, five radio buttons are displayed. Then, users should be able to click on those buttons. It successfully displays the buttons, but when the buttons are clicked, instead of highlighting the selected button, it shrinks the row itself. I think this is probably because I implemented each set of the label part and the option part as a single row, just in different UIViews. I believe clicking on the view that contains buttons is overridden by clicking on the row(label + options). Its really hard to explain, but I think a solution could be restricting selectrow action of the table to only certain portion of the row.
Is there a way I could achieve this? If I cannnot, is there other ways to implement the accordion table to be used as I described?
I am having a really hard time trying to explain this. If you have any questions, please let me know.
table
As per my understanding you van give a try to below steps:
Disable the row selection so that you can avoid row selection. Usecell.selectionStyle = .none
Secondly for your button in row set the IBAction in controller class and in Storyboard connect those actions to specific buttons.

Editing a UITableView that contains dynamic data in each row?

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.

Table View Design Issue

My app design required a page that display 'user information' and i currently have this setup using a simple table view in a View controller. Now, the tricky thing is I need to be able to provide functionality to the user to be able to edit these on the same same screen. So essentially when the user taps on a row in the table view, I want that little flashing text line at the end of the current text in the row so the user can edit what's currently present and I also want a save button to apear on the top when a user has started editing. The tricky part is, not all fields in my table view will be editable. So, I need certain fields to be editable and have the save button appear and certain fields not.
Can you tell me how would I go about modifying my existing design to implement this functionality? I would appreciate some code if you think you can show me how exactly I would go about doing things.
You would probably want to make some custom UITableViewCells. You can fill a tableview with all sorts of different cells which are different sizes and looks different, all at the same time. I would suggest a custom UITableViewCell which will hold a UITextField as one of the subviews. On the cells which you don't want user interaction with the textfield, either make a new custom cell that uses a UILabel or just do textfield.userInteractionEnabled = NO. Look up some custom uitableviewCell tutorials to get you started and then use the approach that I suggested for your problem.

Resources