I have created a custom UICollectionViewCell that contains a UITextField inside of it which is only accessible when the cell is selected. The CollectionView has multi select enabled and the problem is that when trying to select the UITextField to type in it, the cell is deselected instead of giving the TextField focus.
How do I allow focus on the UITextField inside of the CollectionViewCell without causing the cell to be deselected?
Note: I've also tried adding buttons to the cell template and the button actions are not getting called either. It seems as though the cell itself is capturing all of the touch events and not passing them along to child views.
I'm not sure what the original problem was, but I solved it by re-creating the UICollectionViewCell interface inside the UICollectionView in my storyboard instead of loading it from a different .xib file.
Related
Basically I have a UIPageViewController which has multiple UICollectionView on each pages.
The problem is I can select/deselect on collectionViews inside the first page. But when I switch to second page, numberOfSections, numberOfItemsInSection, cellForItemAt are all called however the selection and deselection delegate methods are not called at all.
here is the link to the code:
https://gist.github.com/anonymous/4eca4ff9f3e4423c01974609aeae5482
I can't connect to your link. But you must make sure delegate of UICollectionView was set and check allowsMultipleSelection and allowsSelection is YES. You can reference links below:
UICollectionView - didDeselectItemAtIndexPath not called if cell is selected
iOS: UICollectionView cell selection not working
I have an app that contains an NSTableView instance with 2 columns. One column, is an instance of this:
#import <Cocoa/Cocoa.h>
#class NSTableView;
#interface MMCheckboxTableCellView : NSTableCellView
#property (weak) IBOutlet NSButton *checkboxField;
#end
and the implementation is all boilerplate with no custom code added at all. In code, the NSTableView instance sets tableview.enabled = YES (or NO) programmatically based on various state of the app. When tableview is disabled, the other column of the table, which is display only, stops responding to click actions, as expected. The checkbox column, above, continues to respond to clicks and lets the user check/uncheck the button instances.
To try to troubleshoot this, I added a Text Field (it's not hooked up to anything) in the the checkbox column and when the tableview is disabled, it isn't possible to enter text into the field. Is there something special about NSButton that I'm missing? Is it possible that because I derived this class from NSTableCellView with an added Check Box rather than using a Check Box Cell I'm running into this problem?
I finally figured this out. It appears that even though the NSButton is embedded in the NSTableView, setting enabled=NO on the table doesn't control the behavior of the button. The only thing that eventually made this work was to invoke setEnabled the the control based on the state of the app. This had to happen in the rendering of the cell, so when the state changes, it was also necessary to invoke NSTableView:reloadData so the visible cells would redraw immediately.
As an alternative, I decided to work around this same problem by setting up a computed property matching to my boolean property that returned either a blank or a checkmark character (✓). Then bound to this field as a normal NSTextfield for which the enabling/disabling works.
// Swift
// Computed variables on model for readonly display in table
var bIosText:String {return bIos ? "✓" : " " }
var bAndroidText:String {return bAndroid ? "✓" : " " }
Looks pretty good I think:
Of course this is only part of the solution, if you want to enable editing, you need to have multiple columns and hide/unhide as needed.
Do not embed an NSButton in the table view, only use a NSButtonCell. If your NSTableView was view based, it will switch to cell based (at least Xcode did that for me).
So this is wrong:
And this is right:
It should suffice to disable/enable the table view after this change, the button cell will behave accordingly.
I have a view controller that I have a static view up at the top with a button and a tableview that is under it. I'm attempting to create custom cells in the tableview, but I cannot add labels or anything to the cell. Storyboard only allows me to add the labels to the original view or the tableview (but not the cell). How can I get around this?
Here's a picture for reference.
Out of pure "trying everything" I got it fixed by manually dragging a cell into the view and not using the auto generated prototype cells by xcode. It looks like it was a bug with xcode where it's auto generated prototype cells would not let any interaction happen. To fix it, I dragged a UITableView cell from the object list into the tableview and I was able to edit that just fine. Hope this helps someone else out.
I want to have a button and label who always stick together. I want it to be static and I found a solution which uses the UICollectionView with cells. I got the "Connection "" cannot have a prototype object as its destination" and found a solution here: Strange error when adding items to prototype cells in storyboard-IB but the answer given there is talking about a dynamic one. What is the right way to do this? I don't need to have a #property from the cell, I only need to have a #property from the button and label and I just want the label and button to stick together. So actually something like this:
You should make a UIView with a UIButton and a UILabel as its subviews.
If you want to use UITableView or UICollectionView, this parent UIView will actually be the UITableViewCell or UICollectionViewCell.
I am making my first Mac OS X application and I'm stuck with a problem.
I created a NSTableView on my window linked to a NSArrayController and I'd like to call a method after stopping to edit a textfield cell. So I've selected to call an action when end editing, as you can see in the following screenshot:
After, I've created an IBAction for it:
It generated this code in my AppDelegate.h:
- (IBAction)stopEditingHeaderNameCell:(id)sender;
And then I edited the IBAction in AppDelegate.m in order to show a NSLog message when the cell is edited:
- (IBAction)stopEditingHeaderNameCell:(id)sender
{
NSLog(#"test");
}
However, when I stop editing the cell by pressing enter or clicking in another element, nothing happens. I already tried to apply this IBAction to a NSTextField and it works perfectly, but it doesn't call the IBAction when applied to this text field cell.
Can anyone help me to solve this?
Thanks!
This is not the way you do this with text field cells in a table view. You need to make your app delegate the delegate of the table (you can connect this in IB), and then implement controlTextDidEndEditing:. This method will be called when you end editing (by tabbing out of the cell or clicking on another row or column).