I have a childViewController on a UICollectionViewController. I have so my childViewController appears on the screen. But when I register a cell collectionView?.register(MyCustomCell.self, forCellWithReuseIdentifier: CellId) and use numberOfItemsInSection and cellForItemAt. The problem is that the cells wont appear, I have checked the code so it´s right. Can it be something with the childViewController?
Generally it's not preferred to add any child view or viewController to UICollectionViewController or UITableViewController as you will see un-expected results as both of them inherits from scrollview and make the added content scroll able or scattered any place, if you have then better create a custom viewController with a collectionView and the childViewController
Related
So I have a view for which I have a tapGestureRecogniser. Now I am adding a collection inside the view and relying upon it's didSelectItemAt delegate function to detect any touch inside the collectionView cells. But when I click a cell, only my tapGestureRecogniser function is evoked. Please help how to implement this ?
I have tried setting tapGestureRecogniser.cancelsTouchesInView = false, but this leads to both the tapGesture and didSelect being called when clicked on the collectionview cell.
I have a xib that is a UIView, with class MyUIView. I'd like to re-use this view as a Table View Cell, but I'm not sure how I would do that.
I know I have to register the xib for my table view, like:
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UINib(nibName: "MyUIView", bundle: nil), forCellReuseIdentifier: "MyUIView")
}
But other than that, I'm not not sure how to upcast it to a Table View Cell. What modifications do I need to make to the regular Table View/Table View Cell process to use my UIView xib as the cell?
Add a UIView control to your table view cell. Then set its class to MyUIView.
I'm working UICollectionView and facing issue with contentOffset while reloading the data.
I already read multiple posts regarding this, but couldn't find any solution.
Issue:
UINavigationController -> ViewController1 (rootViewController)
ViewController1 contains a vertical UICollectionView that contains multiple UICollectionViewCells.
On tapping a particular UICollectionViewCell, ViewController2 is pushed into the navigation stack.
Now, on returning back to ViewController1, I'm reloading the UICollectionView which changes the previous contentOffset.
What is required?
I don't want the contentOffset of UICollectionView to be changed when I return back to ViewController1 from ViewController2.
try this code for reloading your collectionView:
let contentOffset = collectionView.contentOffset
collectionView.reloadData()
collectionView.layoutIfNeeded()
collectionView.setContentOffset(contentOffset, animated: false)
I'm trying to create a footer in a table view using Swift. A single footer that's always at the bottom of the screen. I set up a .swift file called TableViewFooter.swift that creates a class called TableViewFooter, a subclass of UITableViewHeaderFooterView. TableViewFooter has 2 labels, a button, and a progress view. In my TableViewController I put the code:
let nib = UINib(nibName: "TableViewFooter", bundle: nil)
tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "TableViewFooter")
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let currSection = fetchedResultsController.sections?[section]
let title = currSection!.name
let cell = self.tableView.dequeueReusableHeaderFooterViewWithIdentifier("TableViewFooter")
let header = cell as! TableViewFooter
header.titleLabel.text = title
return cell
}
I'm getting an "Expected declaration" error after the tableView.registerNib line, a "Use of unresolved identifier 'fetchedResultsController'" error after the let currSection line, and a "Use of unresolved identifier 'header'" error after the header.titleLabel.text line. I'm new at this, but I'm using a Swift file, not a nib, so shouldn't I be putting something else instead? The only tutorials I found are using nibs or the cryptic Apple reference. Any help would be greatly appreciated!
It sounds like you want one of two things:
A UITableView footer. This is a view at the bottom of your UIScrollView, meaning that it only shows when you scroll to the bottom of the table. You can modify this, by accessing the tableViewFooter property of your UITableView, in your view controller, which I assume is your delegate and dataSource.
Or, a view that always remains at the bottom of your screen. This is not a table view footer, but a view that you will add to the main view of your view controller. To do this, add a custom UIView at the bottom of your view, making sure that it does not overlap with your table view (otherwise, the user won't be able to get to the bottom cell), and make sure that the scrollView property of your table view is large enough to contain all of its cells.
I am having trouble on performing a segue when you click on a tableView's cell. I am not using storyboard at all in the application (deleted the storyboard file), and was wondering how I could perform this segue.
Note:
My tableView is in a different file than the viewController that displays it. So in my ViewController i have this line:
let tableView = MyTableView(restaurants_data: restaurants, frame: CGRect(), style: .Plain)
view.addSubview(tableView)
So since MyTableView.swift is the file where the didSelectRowAtIndexPath function is located at I cant do something like
self.navigationController?.showViewController(destinationVC, sender:nil)
So, how do I perform a segue when the user clicks on the cell, given that I am using a custom TableView and my application is not using StoryBoard?
Thanks a lot in advance
Add a reference for the viewController inside your tableView
and initialise it in the viewController init
var controller : UIViewController
controller.presentViewController(viewControllerToPresent: UIViewController, animated: Bool, completion: block?>)