Getting 'Invalid update: exception when trying to delete cell from UICollectionView - swift3

I have a collectionView with isPagingEnabled property true. My each CollectionView cell is same size of ViewController. I am using this collection view like pager.
Now I am trying to delete a cell at 'indexNumber' (Note: I am getting this indexNumber from somewhere else) using below code: -
let deletingIndexPath = IndexPath(item: indexNumber, section: 0) // Line 1
self.collectionViewPager.deleteItems(at: [deletingIndexPath]) // Line 2
self.collectionViewPager.scrollToItem(at: deletingIndexPath, at: UICollectionViewScrollPosition(rawValue: 0), animated: true) // Line 3
I am getting exception at line 2 as mentioned below: -
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (4) must be equal to the number of items contained in that section before the update (4), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
While I am able to insert item in collectioView with below code: -
let insertingIndexPath = IndexPath(item: self.numberOfPages - 1, section: 0)
self.collectionViewPager.insertItems(at: [insertingIndexPath])
self.collectionViewPager.scrollToItem(at: insertingIndexPath, at: UICollectionViewScrollPosition(rawValue: 0), animated: true)
Please help what I am missing in deleting item. Thanks in advance.

I got resolved above issue. This issue was due to I was trying to remove the item from my local array after Line 3. When I put logic to remove the item before Line 1. Got resolved.

Related

MIT AppInventor list Error : Attempt to get item number 0, of the list [5]

" Select list item: Attempt to get item number 0, of the list [5]. The minimum valid item number is 1.
Note: You will not see another error reported for 5 seconds. "
Hey Guys,
The message on top appear when the app open the app not crashing but I need to click somewhere on screen few times till it disappear..
The idea is to search a value of var 'UID' in firebase.database and when it found it I need to get the value of is brother key..
I want you please to help me to clear this message I tried a few ways to get the result but nothing yet..
Thanks a lot for helpers :)
When Screen Open.
This is how I tried to get the uid && employeeKey.
for your help me I set var 'UID' = to uid value of employee number 1
'UID' get the value from firebase.auth form on screen 1..
The index in list block returns 0, if the "thing" has not been found in the list and in this case you are trying to get the value from the 0th item from the empKey list, which does not make sense.
Therefore you will have to add an if statement... if the returned index is 0, then do not search for the empKey.
Btw. the better place to ask questions like this would be the MIT App Inventor community...

Get elements from LazyLoadCollection

I have found Doctrine\Common\Collections\Criteria to be a very useful concept, if they worked for me.
In a symfony controller, I am calling this code:
$criteria = Criteria::create()
->where(Criteria::expr()->gt('position', 0))
->orderBy(['riskPosition', Criteria::ASC]);
$positions= $this->getDoctrine()->getRepository(DataCategory::class)->matching($criteria);
dump($positions->count()); // dumps 1, correct!
dump($positions);
foreach($positions as $r)
dump($r); // -> Unrecognized field: 0
dump($positions) gives
LazyCriteriaCollection {#881 ▼
#entityPersister: JoinedSubclassPersister {#849 ▶}
#criteria: Criteria {#848 ▼
-expression: Comparison {#836 ▶}
-orderings: array:2 [▶]
-firstResult: null
-maxResults: null
}
-count: 1
#collection: null
#initialized: false
}
As soon as I access an element of the returned array, I get an error
ORMException::unrecognizedField(0)
in vendor/doctrine/orm/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php (line 1193)
But as soon as I want to access the elements (e.g. loop and dump) I get some error like An exception has been thrown during the rendering of a template ("Unrecognized field: 0").
As far as I have studied the code, the problem is that the query results have not been fetched from the database. Only count() works. How can I trigger this fetch?
Does it matter that my entity has #ORM\InheritanceType("JOINED")?
This code (circumventing the use of Criteria) does give correct results, but I'd like to use Criteria:
$riskPositions = $this->getDoctrine()->getRepository(DataCategory::class)
->createQueryBuilder('p')
->where('p.position > 0')
->orderBy('p.position', 'ASC')
->getQuery()
->execute();
The issue is caused by line:
->orderBy(['riskPosition', Criteria::ASC]);
Doctrine\Common\Collections\Criteria `s orderBy accepts an array argument where
Keys are field and values are the order, being either ASC or DESC.
github link
Apparently, there is a mistake at doctrine s documentation.
So doctrine thinks that "0", which is the 1st key of the array argument, is the field to sort by, but cannot find it.
To solve, change the above line to:
->orderBy(['riskPosition' => Criteria::ASC]);

IF Formula returning error or not doing a section of the formula

I have a formula in my report to select a field based on requirements:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" and {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT})
else '0'
When I run the report it works ok until I try to load a specific page. When I try to load the page I get an error of 'The string is non numeric'. The formula is called in another formula:
{COR_TBL.COR_EXPECTED_DATE} + 2 + ToNumber({#FRM_NOTES})
I have ran the query on the server of:
SELECT * FROM EXT_TBL WHERE EXT_KEY_TYPE = "SO" AND EXT_ACTION_FLAG_9 = "Y";
This returned me two rows of data. I have narrowed it down to a specific entry that is causing the issue, but in the database the row has N in the field action flag 9 instead of Y so it shouldn't be throwing me the error in my report.
The action field 9 is flagged on only two records both of which contain a 7 in the EXT_TEXT feild so I have no idea why I am getting the error.
I also tried a nested if statement of:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) then
(if {EXT_TBL.EXT_KEY_TYPE} = "SO" then (if {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
then {EXT_TBL.EXT_TEXT}))
else '0'
But it still gave me the same error.
Thanks
I was able to fix the issue by removing the nested if statement and just putting all the conditions in the original statement:
if not isnull({EXT_TBL.EXT_KEY_TYPE}) AND {EXT_TBL.EXT_KEY_TYPE} = "SO"
AND {EXT_TBL.EXT_ACTION_FLAG_9} = "Y"
THEN {EXT_TBL.EXT_TXT} ELSE '0'
This seems to have fixed the issue.

Ionic permanently removing items from tab list

Having an issue with actually clearing out and refreshing list items within a tab view.
A) Within the service, refresh sets the return object to null (verified) calls for fresh data (verified) and returns it to the controller (verified).
B) Within the controller, before refresh is called, i validate the length of the previously returned object(verified as length of 6), then set the object to null (verified as null), refresh the data and then validate the returned object (verified as length of 6 again).
My expectation is for the original list of 6 items to clear out and be replaced with the new list of 6 items. However, the html template list of 6 items grows to a list of 12, basically duplicating the original list. Further more, the new list of 12 seems to be sorted so the duplicates are listed in order as pairs - which seems like its being sorted. I don't understand this behavior and I can't figure out how to get displayed list to actually clear out.
.controller:
$scope.doRefresh = function() {
alert(Object.keys($scope.prods).length) ; // (6)
$scope.prods= {} ;
alert(Object.keys($scope.prods).length) ; // (0)
$scope.prods= Prods.refresh();
alert(Object.keys($scope.prods).length) ; // (6)
}
.service:
refresh: function() {
prods= [] ;
getProds() ;
return prods;
},
I fixed the issue. It was my own code. in "getProds()" I wasn't setting the return object to null, Every time I hit refresh the object was simply adding all the new data onto existing object, and returning back to the controller twice the previous size.

Get last element from arryalist using drools DRL file

I am trying the following code
rule "Last activity"
salience 1
when
$notification : NotificationVO()
lastActivityOffset:Integer()
from $notification.offsetChngesInterval.
get($notification.offsetChngesInterval.size()-1)
then
System.out.println("Hello--"+$notification.offsetChngesInterval.size());
end
It gives error java.lang.reflect.InvocationTargetException.
Can anyone let me know what is causing this problem on the line
$notification.offsetChngesInterval.
get($notification.offsetChngesInterval.size()-1)
It does not allow me to get the last element from the list
It is advisable to write
$notification : NotificationVO( offsetChngesIntervall != null && offsetChngesInterval.size() > 0 )
to make sure that the list isn't empty. Perhaps also a check that it is not null.