UITableView within Subclassed UIView - ios

I have a UIView that I subclassed to use as a slideout menu. Prior to trying to implement a tableview, I had programmatically added buttons with images and titles. It worked fine.
Currently I'm working with a subclassed UIView with a UITableView on top. I have a subclassed UITableViewCell and both subclasses have xibs.
The problem is that I can't seem to figure out how to have the tableview show up. I have the delegate methods in place as well as setting the tableviewcell as the dequeued cell.
The question I would like to figure out is how to get the tableview to show up. The background of the menu shows up but no tableview on top. Thanks for the help.

Related

UITableView shows under status bar and i want status bar to be opaque so that tableview data doesn't overlap with statusbar

iOS 7: UITableView shows under status bar
I tried all the links and solution but it's not working for me. I have 13 fields to get from the user and each textfield is in a cell of tableview . My tableview have static cells so if I use UIViewController and put a tableview inside it I have to write UITableViewCell classes for each cell because the design of each cell is different and that is very lengthy work to do.
You can put the tableView in the normal UIViewController and then set the content to static cells in the attributes inspector.
This way you can put your custom cells and then access the controls directly inside the UIViewController class.

How to resize UIView with dynamic tableview in it?

I am using storyboard.I used one UIButton to show/hide UIView and I already added one tableView to UIView and getting tableView and all.In tableView it is loading dynamic datas.But the problem is that UIView is not resizing with this tableView.I added few constraints and yet it is not working.Can somebody suggest an answer?

Adding SearchBar to CollectionView

I've created a CollectionView (as a CollectionViewController in IB) and it occurred to me that I should have a search function.
I want to add a SearchBar above my CollectionView in Storyboard, however it physically will not allow me and keeps sliding below which obviously won't work.
Is there a way to get around this, or do I need to rebuild my CollectionViewController from scratch with SearchBar at the top?
Can I add the SearchBar programmatically to the existing CollectionViewController?
See picture for reference:
I think the easiest way is to copy your collectionview to UIViewController & setting it to be delegate & datasource.
This way will allow you to add a searchbar above collectionview.
you can further detect searchbar text change & apply changes to collection view data.

UIScrollView within UICollectionViewCell Not Working

I have a UICollectionView with a custom UICollectionViewCell. The UICollectionView scrolls horizontally, with each cell occupying all of the visible screen.
The UICollectionViewCell has a UIView subview, which in turn has a UIScrollView subview.
The UIScrollView is intended to scroll vertically, but it's not scrolling at all. I've tried setting the scroll view's contentSize with no success.
I suspect that the UIScrollView is not getting any touch events rather than it being a size issue.
Any suggestions?
EDIT >>
I'm now sure it's an event problem rather than anything specific to the UIScrollView.
I've now overridden the pointInside: method in the UIView in the UICollectionViewCell and can see that it now returns false every time I tap on it. In that case you'd think that the tap event would propagate to the next subview , but the UIView still isn't getting events. I've tried adding a UIGestureRecognizer to the UIView but it never registers a tap.
Could there be anything here intercepting the events that I'm not aware of?
I've been trying to solve a similar problem with a scrollview, and your edit about events reminded me of this question (which solved my problem again) How can I use a UIButton in a UICollection supplementary view?
Its possible you need to be using a UICollectionReusableView, not a UICollectionViewCell. Changing the class worked for me because I was using a button (and recently a scrollview) in a header.
However I've not tried for cells themselves. For capturing events from a UICollectionViewCell, maybe the following may help?
Getting button action : UICollectionView Cell
Try to disable userInteractionEnabled for the UIView and enable it for your UIScrollView
I'm not sure if this was your problem, but it was mine - and I'm putting it here in case anyone else comes across this for the same reason. I wanted to put a UIScrollView inside a UICollectionReusableView but by accident I had created my custom class as;
class CustomCellHeader: UICollectionViewCell {
}
instead of;
class CustomCellHeader: UICollectionReusableView {
}
Once I changed that, the UIScrollView within my header cell came to life!
Embed the scrollable content in a ScrollView within the cell.
Add "UICollectionViewDelegateFlowLayout" to the UICollectionViewCell i.e.:
class SomeCollectionCell: UICollectionViewCell, UICollectionViewDelegateFlowLayout {
}
Now scrolling within the cell should work.

Adding subviews on a UITableView

I'm working on a project were I use mostly UITableViews. The user enters data and the App gives the result of a calculation. I have two buttons: "Calculate" and "Reset". I want to add a subview containing these two buttons and have them displayed at the bottom of the screen. By Storyboards, I can add the subview, but it sticks to the button of the UITableView, not the screen.
Any idea on how to accomplish that? Should I mess with the constrains between the subview with the buttons and self.tableview.superview ?
Any help is appreciated!
You can use a standard UIViewController instead of a UITableViewController, and add a UITableView to your view controller. You can then place subviews at will.
Do not forget to connect datasource and delegate of your tableview.

Resources