Im trying to include a tap to open screen on my playground that then allows users to see my chart. I want them to first tap through 3 or 4 screens with different information before loading to my main page.
Ive tried searching up tutorials (Im new at this), but cant find any that help me.
So this is the code to show my table view and need help implementing the tap screens
class HOCMasterViewController: UITableViewController {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return reasons.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell: UITableViewCell!
cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
My table appears, just need to add the UI for the tap screens!
First of all the information screens that you need users to tap through. How are they being displayed? Are you using simple UIViews? Kindly give us some info on that? If you are using different UIViews on which you are showing information, then I would simply hide the previous UIView/ remove it from superView and add the next UIView and so on!
So your playground loads and when you tap on the screen by using a UITapGestureRecognizer and in the selector function you count the taps and according to each tap, you can hide or show the UIViews / or animate the constraints / frames of each UIView. Then after 3 taps you can show the TableViewController.
Kindly provide us with the information screen code.
Related
I am very new to Swift, object-oriented programming, and interface building (I only have experience with some MATLAB programming), and I have been struggling for about a week to come up with a working interface in the IB. I have tried lots of permutations of View Controllers the Container View with and without a UIButton connected to a segue and with and without a Navigation Controller, and I am out of ideas about what to try at this point (the Stack Overflow pages I've looked at ended up created more bugs with what I wanted to do).
Ultimately, I want the user to be able to use UIButton to navigate between six UIViewControllers that are inside a Container View in a View Controller (sort of like a manually-operated slide show between the views). I have tried UITabBarController and UINavigationController, but I don't want the tab or navigation bars.
I apologize in advance for not providing any code, but I literally learned Swift a month ago, and am sort of learning as I go along. I have uploaded one of my attempts in the IB though (two out of six UIViewControllers are shown because I haven't put all of them in yet due to the bugs). In the attached image, the second view is placed on top of the first rather than just in the Container View. the image is on the URL since I cannot attach it to this postThank you for any help that you can provide.
How I would do it is pretty straight forward. Create a collection view with so many number of cells as you need Views. Lets say 5.
Each cell has its own UIView with an embedded ViewController. You do that 5 times for each view. That should be the difficult part.
The next thing would be to create the button I guess you have 2 buttons one back < and one forward >. Then simple logic on button press and in the collection view you just increment to the next page using this:
[self.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
That should do the trick.
An example on how to change the cell size
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
// your code here
}
For different views for each cell you create a cellId1, cellId2, cellId3 etc. And register a new cell for each cell id.
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
This would be how to set a different cell for the views
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
return cell
}
This should be really enough to get you going.
I will try to explain my problem with the help of pictures :
Firstly, I just added an UITableView to my UIViewController. I selected it to show its frame and there was no problem.
Next, when I connect my button to my UIViewController, my UITableView gets smaller.
I selected it to see that the frame doesn't match with the contents. I noticed that the tableview reduces exactly of 64 (44 from the UINavigationBar + 20 from the bar with the battery)
At the beginning, I thought it was juste a display problem from XCode, but next when I tried to run it with cells, the problem still exist.
So I put a UIContainerView in my UIViewController and my tableView in the controller of the container. XCode display properly my table view, but when in run it, I get the same problem.
Thank you in advance,
Sorry for my english.
The problem is that your containing view controller's Adjust Scroll View Insets is checked (in its Attributes inspector). Uncheck it.
You can use this function to explicitly set the size of your cell.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
}
Background: I'm making a calendar and for that I'm combining a UITableView and a UICollectionViews. The UITableView is holding month cells. Each month UITableViewCell is holding a UICollectionView with UICollectionViewCell days.
Problem: The UICollectionViewCells aren't clickable.
I can fix this by calling self.bringSubviewToFront(self.collectionView) in the month UITableViewCell. However this makes the UITableView not scroll because the collectionView is now top view.
So, I can either choose between be able to scroll the UITableView or be able to click the UICollectionView.
What I tried: I tried to capture the click before it happens and bring the collectionView to front and then put it back again. Not a good solution though:
//In UITableViewCell class
//UIGestureRecognizerDelegate
//Bring collectionView to front before tap
override func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
self.bringSubviewToFront(self.collectionView)
return true
}
//UIScrollViewDelegate
//Bring collectionView to back again
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
self.sendSubviewToBack(self.collectionView)
//Do stuff
}
Question: How can I achieve to both be able to scroll and have the UICollectionView clickable without bringing back and forward the view between taps? Is there a way to have the UICollectionView in front and still make the UITableView scrollable?
Nested UIScrollView with same scroll directions is against Apple's Human Interface Guidelines and your app might even get rejected for this so try disabling the scroll of your UICollectionView.
Hope this helps.
Description:
I have a list of UITableViewCells that have each have a UICollectionView with X amount of UICollectionViewCells (see image below for more clarity)
The idea behind this is to be able to implement sections with a header on top and a horizontal scrolling UICollectionView
Everything is working great, except when I try to focus the UICollectionViewCells (aka: CategoryCell). The UITableViewCell gets focused and highlights all the content making it impossible to focus any of the UICollectionViewCells.
What I've tried:
According to other posts the fix for this would be deactivate User Interaction and/or set the selection style to none on the UITableViewCell:
cell.selectionStyle = UITableViewCellSelectionStyle.None
and to enable User Interaction on the UICollectionViewCell instead.
Here are posts that talk about it:
UITableViewCell with UITextField losing the ability to select UITableView row?
How can I disable the UITableView selection highlighting?
I've attempted to implemen these solutions without success.
Question:
What step did I miss? Does the fix not work on tvOS? How do I focus my UICollectionViewCell that is in a UICollectionView that is in a UITableViewCell?
More:
Image showing my UITableViewController and all it's contents from my StoryBoard.
The problem is most likely that your table view cells are returning true to canBecomeFocused. You can disable that by either implementing the UITableViewDelegate method tableView(_, canFocusRowAt:) to return false, or by subclassing UITableViewCell and returning false from canBecomeFocused.
The focus engine will try to focus on the top-most view that returns true from canBecomeFocused, which is why it can't find your collection view cells: they're "hidden" inside the focusable table view cells. If you disable focus on the table view cells, then the focus engine will be able to find your collection view cells.
override func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
I am trying to change the default left minus icon for a cell in edit mode.
I tried everything.
I am already able to change the Delete confirmation button on the right, I need only to change the left icon.
I tried to create a custom interface cell and added a custom image on the left side, then I have added this code in my view controller.
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.None
}
Adding that code gives me a way to hide the minus default icon and showing my own image.
The problem is that the space for the default icon remains anyway :(
I do not know what else to do. I tried using constraints in my custom cell interface, but it does not fix the issue at all.
Also when using that piece of code anyway, not only the icon goes away (that's fine apart from the white space that it leaves) but also does not show anymore the right actions when swiping. Only the drag and drop feature reamains active.
func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
add this function so the rows wont indent while editing