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.
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 currently have a table view with all my cell names which when clicking on a specific cell you will be directed to that page with the use of a segue between the two to keep them linked, which is fine for example click the Hello cell and the hello page will be displayed. I have a label linked within the second view controller to match the cells name when loaded so that it only loads content specific to that cell. Now I'm attempting to add an embedded container view within my second view and I want it to work in the same way. For example person click Hello cell, Hello view controller appear and content within container is relevant to that cell as well. Currently the label inside the main view controller controls what content goes in, how would I got about adding a label within the container view controller with the same concept. (Second view controller and container view controller should have same label title when cell clicked)
I'd suggest looking at prepareForSegue and passing a parameter property that way. Then in the destination view controller you can parse that and switch content based on it.
https://developer.apple.com/library/mac/documentation/AppKit/Reference/NSSeguePerforming_Protocol/#//apple_ref/occ/intfm/NSSeguePerforming/prepareForSegue:sender:
So I have a UITableView that navigates to a detail view when a cell is selected. Each cell and it's detail view passes through different data depending on which cell is selected. On the storyboard it is one generic detail view with a text label and an image view that loads in data from an array.
What I want to do is navigate from the current detail view to the next detail view (for the next item in the table) without having to go back to the main table view controller. How can I do this? I would like to do this with a button.
I have looked at this but I can't seem to get it right/not sure it's exactly the same thing: Navigate between sibling detail views of a parent table view
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?
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.