I'm using a series of ImageCheckRow as a selection, and I'm trying to disable some of the entries that I don't want changed.
row.disabled = Condition(booleanLiteral: disableEntry!)
row.evaluateDisabled()
However the rows aren't disabled.
The full section of code is in the original StackOverflow entry.
https://stackoverflow.com/questions/44513407/how-to-disable-an-imagecheckrow
Cheers
Murray
Hi @murraycollingwood, your code looks correct to me, can you check that the disableEntry
becomes true
in some case, maybe you can use true
as default value to see if something change.
You can try running the examples to check it, with a small change in the ListSectionsController
you will have a pretty similar example running:
// NOTE: Some code was removed from the example for simplicity
// Disable condition
let disabled = true
for option in continents {
form.last! <<< ImageCheckRow<String>(option){ lrow in
// Add these two lines after the code in the example provided
lrow.disabled = Condition(booleanLiteral: disabled)
lrow.evaluateDisabled()
}
}
for option in oceans {
form.last! <<< ImageCheckRow<String>(option){ lrow in
// Add these two lines after the code in the example provided
lrow.disabled = Condition(booleanLiteral: disabled)
lrow.evaluateDisabled()
}
}
You can see the result in the GIF bellow:
Hi @m-revetria and thank you for your response.
We are definitely getting some true and some false values coming through.
I made those changes to the Examples as suggested and you are correct - they disabled as expected.
I've spent the morning applying aspects of my code to the examples in order to find the point at which they break - so far I haven't been able to do so, and the Examples are beginning to look a lot like my code yet the disable option continues to function correctly.
How did you make that GIF? Perhaps if I made one and sent it back you would see what I'm getting, there is a slight difference in the way the control operates, but it is still changing image when checked and unchecked however the dark grey persists on the disabled rows.
I add this to the Example code:
lrow.disabled = Condition(booleanLiteral: true)
lrow.evaluateDisabled()
print("row.isDisabled = (lrow.isDisabled)")
And the output repeated:
row.isDisabled = false
However the Example controls are still disabled.
Almost thought I had a break through - alas this is not the problem.
Still, we should be able to test the disabled status at this point - yes / no?
So I finally copied the Example code into my viewDidLoad()
Running in the Example app the disabled controls were DISABLED.
Running the same code in my app the disabled controls were ENABLED.
Where should I be looking now?
@murraycollingwood I used LICEcap to make the GIF, pretty easy to use.
Printing the evaluation of isDisabled
is showing false because at the moment evaluateDisabled
is called in the sample code that I posted, the rows weren't added to the form yet, so the evaluation is not fired. I shouldn't have included the evaluateDisabled
call as it is not needed in the row creation callback. Actually it does nothing. So you should not check if the row is disabled in that step using the property isDisabled
.
If you put next line after the for
loops in the example you will see that isDisabled
is true.
form.allRows.map { $0.isDisabled }.forEach { debugPrint("row isDisabled = \($0)") }
Coming back to your issue, isn't the same code working in your project? What version of Eureka are you using there? Could you let us know which environment are you targeting?
Have you added a default cellSetup
block in your project that might be changing the disabled value? Or any other default callback like cellUpdate
?
We're now getting: "row isDisabled = true" on the appropriate lines, so the disabling is being set, however the controls are not disabled, clicking still changes the image.
I believe I'm using Eureka-forms 1.5.1, but is there a way I can be sure?
Can I do this? print("(EurekaVersionNumber)")
I haven't added anything else to the form, I literally copied the working code from the Examples ViewController.swift, ListSectionsController, viewDidLoad function to my viewDidLoad function, and it failed due to missing image. So I added the specification of the cellSetup for my local images. Ran my app and while the rows are now disabled they are still clickable.
This is the code I copied over to my viewDidLoad function:
let continents = ["Africa", "Antarctica", "Asia", "Australia", "Europe", "North America", "South America"]
form +++ SelectableSection<ImageCheckRow<String>>() { section in
section.header = HeaderFooterView(title: "Where do you live?")
}
for option in continents {
form.last! <<< ImageCheckRow<String>(option){ lrow in
lrow.title = option
lrow.selectableValue = option
lrow.value = nil
lrow.disabled = Condition(booleanLiteral: true)
}.cellSetup { cell, _ in
cell.trueImage = UIImage(named: "images/radio-checked")!
cell.falseImage = UIImage(named: "images/radio-unchecked")!
}
}
When I run the app I get a list of continents and each is clickable and the radio-checked/radio-unchecked images changes each time I click on an entry.
I'm using Swift 3
I'm using Xcode 8.3.3
My deployment target is iOS8 (similar to the Example)
My simulation is an iPhone 6 running iOS 10.3 (I set the Example to use this and it disables correctly)
Where else should I be checking?
Sorry this is taking so long to solve.
You can see the installed Eureka's version by checking the file Podfile.lock
if using Cocoapods, there you should see a line like - Eureka (X.Y.Z)
. If you are using Carthage, then you can check your current Eureka version in the file Cartfile.resolved
, you should see a line like github "xmartlabs/Eureka" "X.Y.Z"
.
Notice that when I asked about the default callbacks, they can be added in any place in the app, there is not needed add them in the Form view controller itself. You are able to add this kind of global listeners that might change the state of the rows depending on your implementation in other part of the app, like bellow:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Other stuff
EmailRow.defaultCellUpdate = { cell, row in
row.disabled = false // This will affect all the EmailRow used in the app
}
return true
}
Cartfile.resolved: github "xmartlabs/Eureka" "3.0.0"
I can assure you, there is no other access to the form, nor any other processing until a 'Save' or a 'Cancel' button is pressed.
Some more debugging
Added this code to the class
override func valueHasBeenChanged(for row: BaseRow, oldValue: Any?, newValue: Any?) {
print("row isDisabled = \(row.isDisabled)")
print("Single Selection:\((row.section as! SelectableSection<ImageCheckRow<String>>).selectedRow()?.baseValue ?? "No row selected")")
}
And the output when selecting the first 3 entries
row isDisabled = true
Single Selection:Africa
row isDisabled = true
Single Selection:No row selected
row isDisabled = true
Single Selection:Antarctica
row isDisabled = true
Single Selection:No row selected
row isDisabled = true
Single Selection:Asia
Not sure where to go from here?
I'm really hoping you have some more ideas?
The problem is that libraries of eureka in example and from pods are a bit different. So, to solve this problem do the following :-
Go to your eureka library file SelectableSection.Swift
Now in this file find function
func prepare(selectableRows rows: [BaseRow]) {
In this function change line 4 i.e.
guard let s = self else { return }
to
guard let s = self, !row.isDisabled else { return }
It solved the disabled problem in my project. Do tell if it solved your problem
Thank you for helping with this Deepansh
So I checked the code and it appears exactly as you have said it should, however I downloaded the Eureka framework using Carthage. So I got a copy of the source code, but I also downloaded a ready made framework, and I'm guessing perhaps it has the old code.
So, how does one compile a new framework?
I've open the Eureka.xcodeproj
I've run the build command
It suggests that the build output is at this location: /Users/murray/Library/Developer/Xcode/DerivedData/Eureka-brfskmgpqwzybkcxyxopbvzdcrku/Build/Products/Debug-iphonesimulator/Eureka.framework
Does that seem right?
Anyways, I copied this to a friendlier location and then imported it into my app project. It looks correct - the correct framework name appears and it looks like a suitcase. However, when I try and compile my application I get the error: /Users/murray/dev/sobs-app/SOBS/SOBS/ImagePickerController.swift:26:8: No such module 'Eureka'
I'm doing something wrong. Do you have some instructions for building the framework that you could share?
Thanks @deepanshg I wasn't aware of that issue, and that it was solved. The last tag 3.0.0
doesn't include the fix.
@murraycollingwood, meanwhile there is not a new release, you can point to the latest commit in master "cd0a057a2612286340e5b7f8ba5d06e6fcd4e2bd" in your Cartfile, this should solve the issue.
@m-revetria There are many differences in core library files from pods(i.e. tag 3.0.0) and that of example. Due to these differences certain functions like hidden and disabled are not working properly in 3.0.0. But why these differences exist?
@deepanshg The podspec is pointing to the tag 3.0.0
. This fix and some others were made after we release that version. These changes will be available from Cocoapods when we make a new release. All the changes made after commit cd0a057a are not included in the version 3.0.0
.
Meanwhile you can point to the latest commit in master in your Podfile.
Hurrah! The disabled setting is now working.
Just for documentation purposes the steps in retrieving and loading this version:
Change the line in the cartfile to read like this:
github "xmartlabs/Eureka" "master"
Then run the command: cartfile update
Because I had tried building my own framework I had to delete that one and reload the newly built framework from the folder ./Carthage/Build/iOS/Eureka.framework
Cool, I'm glad to hear that is now working. I'm closing the issue.
Cheers
Most helpful comment
The problem is that libraries of eureka in example and from pods are a bit different. So, to solve this problem do the following :-
Go to your eureka library file SelectableSection.Swift
Now in this file find function
func prepare(selectableRows rows: [BaseRow]) {
In this function change line 4 i.e.
guard let s = self else { return }
to
guard let s = self, !row.isDisabled else { return }
It solved the disabled problem in my project. Do tell if it solved your problem