I have a view which is used for updating the content of a table cell and adding new cells to a table.
Updating the content of a table cell can be achieved by touching a cell. In this case the view will be instantiated programmatically and the data of the cell will be sent to the view. Adding new cells to the table can be achieved by clicking on a button which will show the view as a segue without data.
The navigation bar of the view contains a save button which will update the data of the cell or add a new cell.
I thought about setting a boolean value in the view to detect if the purpose is updating or adding a cell but I don’t think that this would be the right way. What is the best solution for this problem?
Related
I have a collection view where each cell has a video (played through AVPlayer) and a red circle. When a button in the view controller is clicked, the color of all cell's circles should be changed to blue, and then if clicked again, changes it back to red.
So what I need to be able to do is: when the button is clicked in the controller view, change the circle view in all cells, visible or not. The reason I say visible or not is because I only show one cell on the screen at a time. The user swipes to go to the next cell.
I have already tried using reloadData() to update all cell's circles when the button is clicked, however, the problem I discovered is that the video resets back to the beginning (and I need it not to do that, not just for the visible cell, but for all cells).
What are my other options?
When a button in the view controller is tapped you would need to change the data/collection/array of data that you are loading in your collection view. In order to achieve the result in (for example didSelectItemAtIndexPath:(NSIndexPath *)indexPath) you should change the data model for that specific cell/collection item. You can add for instance property isSelected for your collection view data model(s).
In your case, calling reload data calls all the UICollectionViewDelegate & UICollectionViewDataSourcemethods, however since you have not change the data using, the result/UI returns to the initial state.
I want to show table view cell showing edit options by default without applying swipe at the initial launch of the table view. I have tried setting tableView.edit actions property to true but it is not swiping the cell. It is only showing a delete button with action set to swipe. I want to perform swipe automatically at viewDidLoad()
Actually, there is no way to do that. Apple doesn't provide an edit mode on the UITableViewCell. Whereas UITableView has it.
Maybe there is a workaround for the problem you are trying to solve.
In one of the problems, I had where we wanted to let our users know that the table view cell has actions on top of them. What we did was added a custom view on top of the cell and did some animations to show the user actions.
I am doing something similar to whatsapp message info, when dragged the right chat bubble to left it shows message info in another VC.
I replicated this functionality and passing reference of cell which I am dragging to next VC.
But when I come back the cell is disappeared which reference I passed, when scrolled up and down or refreshing the table make it appear again.
Why this is happening I am only passing the reference.
If you are displaying the cell (the same cell from the tableview) in a new view using addSubview:, then that view (the cell) dissapears from its previous superview. A view can only have one superview. IOW, a view can be only on one place.
Don't show the cell in the next scene (view controller). Instead build a new view (or cell) similar to the original.
BTW don't pass the cell to next VC. It is not a good practice. Try to pass data to view controllers, not views that depends on other view controllers.
Im building my iphone application and this is how my storyboard looks right now.
First question: Adding another table view
My first two tab bar items are going to contain table views. Now as you can see i have my first table view connected and all, how would i do to get the empty view under Navigation Controller to be a a Table View. Would i need to add another Navigation controller? or how does it work cause i have never worked with tabbars/tableviews before.
Second question: Customize prototype cell
My first Table View can show the data that i inputed as you will see in the following picture. The first picture is how its currently being shown. How can i make a custom prototype cell that would look like the second picture?
Please not that the cells will be very much alike each other in both of my table views. I will have an if statement where i will check a specific thing and if its true it will hide for example the image but all the other things would be the same so would i make a class for the cells?
For better solving your questions, You must first understand the purpose of Navigation Controller. Navigation Controller is there for you to push and pop between controllers, which is convenient when you have levels of data. It manages a stack of controllers. You don't always need a navigation controller to work with tableview. However, it's a common practice to put Navigation controller and TableView (with view controller or solely UITableViewController) together for easy showing levels of data.
Basically, there are two ways to add a TableView. You can directly drag a table view onto your empty view controller or delete the empty VC, then drag a UITableViewController. Most importantly, select the whole VC and go to Editor (at the top) choose embed in a Navigation Controller.
Link about navigation controller from Apple's document
Since you use storyboard, you can directly customize your tableViewcell in storyboard. You already have a prototype cell. You can now directly drag UIImage or Label on that. Most importantly, create a class subclassing UITableViewCell and connect objects in your tableViewCell as an IBOutlet so that you can control it. If you feel plain text explanation is not enough, I find a tutorial for you.
You could refer to the link section Prototype Cells.
1) Yes you will need a 2nd navigation controller for each tab.
Delete the UIViewController.
Drag a UITableViewController to the storyboard.
Embed the UITableViewController in a NavigationController.
Set a segue from the tab bar button to the new NavigationController.
2)
To fully set up the prototype cell you showed you will need to create a new class which subclasses UITableViewCell and then set IBOutlets for all the labels etc.
How can I put a segmented control on top of a tableview. I don't want it on the title view of the navigation controller and I don't want it to scroll with the tableview either. For reference of what I mean, please look at App Store app, choose Categories, then select any category. There you will see the segmented control I'm looking for. The one with 'Paid', 'Free', and 'Release Date' segments. I'm using the code not IB, so if you know how please answer this with code not IB drag and drop.
When you need other components in a table view controller other than the table view, you can't use a UITableViewController. You need to use a UIViewController. You add the UITableView as a subview and you make the view controller the table view's data source and delegate. Then you can add any other components to the view controller's view as well. This way the additional components don't scroll with the table view. There's a little more plumbing to do to get the view controller to behave exactly like a table view controller. This includes overriding the setEditing:animated: method to set the editing property of the table view. It includes deselecting any currently selected row in the viewWillAppear: method.
UITableViewController has the table view as its view. This prevents you from adding any other subview to the table view controller in a way that they won't scroll.