UICollectionview and/or UITableview cells not selectable until after view scrolled? - ios

For every collectionview and tableview within my app, none of them are recognising the selection of a cell unit AFTER the table or collection has been scrolled a little?
This only happens within this current app, no different methods have been used, no collection/table subclassing etc. All collection views and table views are implemented with all relevant dataSource and Delegates hooked up and implemented etc.
As this is a common thing will all my tables, I'm wondering if it is a setting within the project that is causing this.
If anyone has experienced and previously solved this issue, I'd appreciate any help.
Salient points that may be relevant -
-All collecitonviews / tableviews are set up on storyboard.
-All cells are added directly to table/collection within storyboard and cell view configured using their own class files.
-Deployment target 7.0 for iPhone only
-All tables/collection cells are loading fine, everything looks fine with no crashes... just that the tables need 'woken up' so to speak?
Thanks in advance,
Jim

I've had similar issue, and I fixed it by subclassing UICollectionViewCell/UITableViewCell and setting selected property to NO in prepareForReuse method.
- (void)prepareForReuse
{
self.selected = NO;
}

Related

CollectionView nested inside Collectionview

I have seen solutions where a collection view is nested inside a table view but for my app I need to have 2 collection views as it makes it easier to do some other things.
So lets call the root collection view VerticalCollectionView which only scrolls vertically and the nested collection view HorizontalCollectionView which only scrolls horizontally. I created them using the Storyboard. Below you'll see the orange is the Vertical with the green Horizontal with a label inside it.
And I have set the delegate & datasource of both collections to the same CollectionViewController.
I distinguish between the 2 different cells by checking which tableview the delegate method is referencing as such
My problem is that HorizontalCollectionView isn't getting instantiated. I have everything working for VerticalCollectionView, the background color, the number of items, etc. In the VerticalCollectionViewCell, I have an IBOutlet referencing HorizontalCollectionView
I have used nested collectionViews in my recent app a lot. at first it didn't work for me but when I learned its away it became pretty simple.
instead of setting the HorizontalCollectionView delegate and dataSource to the same CollectionViewController make a UICollectionViewCell and set the delegates and dataSource in awakeFromNib() function of the cell and write the HorizontalCollectionView functions in that cell. it works like a charm ;)
if you needed more detailed answer let me know.
In case someone is looking here since WWDC 19, Apple has introduced CompositionalLayout for UICollectionViews which make these tasks much much easier.
One should read here:
https://developer.apple.com/videos/play/wwdc2019/215/

Issue with programmatically added buttons

I have a cell in the UITableView. The cell has a UITableViewCell class. In this class I programmatically add few buttons.
Note: the cell is located in the very end of the table view.
Issue:
If I'm using simulator iphone 5 > the buttons will be shown.
But if I'm using simulator iphone 6+ > the buttons will NOT be shown.
Note: when i'm opening it on iphone 5 I need to scroll to see that particular cell. on iphone 6+ i don't need to scroll there, the cell is visible right away.
So I think the issue is somewhere here. May be with the place where I do my 'buttons adding'.
Where should I call the method that sets up the buttons?
Or how can I solve this problem?
TL;DR: If you have different cell types in your table view, you should make sure they have different identifiers.
Explanation:
Table cells are re-used within the UITableView and when the table is first being displayed it won't have any re-usable cells yet. It gets the cells to display by calling on its data source through the UITableViewDataSource protocol.
The thing providing the cells will first ask the table view if it has any re-usable cells (of a particular type), before creating a new one. The way it determines the particular type is from the reuseIdentifier in the table cell.
So, if you have two different classes of table cell, but they share the same reuseIdentifier you will sometimes get one class and sometimes the other - if you get the one without buttons when you're expecting the buttons then this will be a problem!
The answer is to make sure your different cell types have a unique reuseIdentifier.

Unable to use Static Cells in UITableViewController

I need to use static cells in my app. I am using Xcode 5 and testing thins on iOS 7 simulator (iPad).
I dragged out a new UITableViewController in storyboard and set the tableview's cells to be static. Then I added a Label to the first cell to check if static cells are working. I ran the app and I got blank cells (dynamic form).
Then I added a class that implements the datasource and delegate methods of a table and attached it to the controller in storyboard. Yet, nothing happened. Finally, I embedded it in a UINavigationController and still, I get plain blank cells like the one below:
Could you tell me whats going wrong here, i.e., why wont my static cells show up!?
Regards
if you use static cells you dont need the datasource. so delete all methods that belongs to datasource, such as cellForRowAtIndexPath. After deleting the methods your label should appear.

Why can't I edit multiple dynamic prototypes in UITableView?

I'm creating a Table View in Interface Builder (Storyboard). I'd like to have a couple of different Dynamic Prototype cells with different sets of Labels and Images in them and so on, and I can give them different reuseIdentifiers so I can pick which ones I want at runtime.
In Interface Builder, I create several Dynamic Prototype cells in my UITableView, which is controlled by a UITableViewController.
In the first cell, I drag and drop in various views and so on.
In the second cell, IB will not let me drag any views into it? I can resize the second cell vertically, but can't put anything into it at all, either by dragging into the cell or into the object graph in the left-side bar.
If I copy and paste the first cell, a second Dynamic Prototype will appear with all of the same contents, but I won't be able to modify the copied cell (can't add or move subviews). However--and this is strange--I can select the constraints and modify their values to resize and shift objects in the second cell.
As a note, running XCode 5-DP3. Tried restarting it (didn't expect that to help, and it didn't). Otherwise, unsure what to try, and unsure if I'm doing something very braindead, or if this is a bug I need to report to Apple.
So, am I crazy? Has anyone experienced this/can anyone recreate this?
EDIT:
After further testing, if I stick a big UIView into the first cell, and then copy that cell, I can edit inside my added view. (Does this make sense?) I can't edit anything that lies within the second UITableViewCell, but if it contains a UIView copied over from the first cell, I can put new views into that view and move them around and so on. Super-strange.
For the sake of posterity, I'm answering my own question:
The way I solved this was to take a UITableViewCell object from the Object library and drag it onto the UITableView. Sounds simple, right?
The problem I was running into was only if I copied existing dynamic prototypes through Cmd+C & Cmd+V, or by incrementing the number in the Attributes inspector for the table view. The Storyboard Editor wouldn't allow me to modify those ones.
Dropping in new cells from the Object library let me tweak them all separately.
XCode 5-DP6 solved issues with not abling to resize cell's subviews.

Custom UITableViewCell class in Xcode 4.2

I've been following this Apple Doc to add a custom UITableViewCell that I layed out in an .xib to my project. One problem with the doc is that it seems like it was written for an older version of Xcode.
I'm able to load my UITableViewController that the custom cells are on, but the cells are all blank. My custom cell contains several UILabels, and has a non-default background color. The table that appears when I run has the default white background and no labels. If I change the UITableView's View -> Background on my storyboard, the color of the cells' background changes, but the labels still don't appear.
Of interest is the fact that the data is still in my table's cells. The UITableViewController is itself called as a popover from another controller. When I select one of the cells, the strings from the various label.texts are supposed to be loaded into their own labels on the popover's delegate, and that code works fine (except when I try to include a UINavigationBar in my popover, but that's probably another issue entirely).
I'm still pretty new to iOS developement, so if there's anything I'm leaving out or being unclear about let me know.
Edit - cleaned up code, now is completely different question than when I originally posted, but is still on the same topic. Should I have deleted the old question and posted this as a new question all together, or is it alright that I just edited it?
I'm still not entirely sure what was wrong with what I was doing before, but I managed to get what I wanted. I originally dropped a UITableViewController onto my storyboard set up a popover segue (also on the storyboard) and tried to display the popover with performSegueWithIdentifier. Instead, I now create the popover completely in my code (which I found a nice tutorial for here on SO, by goggling "show popover programmaticly"), without having anything for it on my storyboard. That seems to be the most documented and stable way to show a popover. Once I displayed it that way, my custom cells showed up exactly like I wanted.

Resources