在UICollectionView中在当前索引之前添加对象(Adding an object before the current index in UICollectionView)
我有一个简单的集合视图,有两种类型的单元格。 计数器单元和“添加”单元。 我的目标是在添加新对象后将“添加”单元格保留在索引的末尾。 当我运行应用程序时,我的“添加”单元格出现,但是当按下“添加”按钮时出现错误。
这是错误:
由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序,原因:'无效更新:第0节中的项目无效。更新后的现有部分中包含的项目数(1)必须等于该项目中包含的项目数更新前的部分(1),加上或减去从该部分插入或删除的项目数(插入1个,删除0个),加上或减去移入或移出该部分的项目数量(0移入,0移动)出)。”
这是我的代码:
// retrievedCounters is an NSMutableDictionary - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { // only want one section return 1; } - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { // get the current count and add one for the "add" cell return retrievedCounters.count + 1; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell; // check whether the index path is at the very end and add the appropriate cell if (indexPath.row == retrievedCounters.count) { cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AddCounter" forIndexPath:indexPath]; } else { cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CounterCell" forIndexPath:indexPath]; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; // insert new counter at index path [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:retrievedCounters.count-1 inSection:0]]]; }
谢谢任何可以提供帮助的人!
I have a simple collection view that has two types of cells. A counter cell, and an "add" cell. My goal is to have the "add" cell remain at the end of the index after new objects are added. When I run the application my "add" cell appears but I get an error when the "add" button is pressed.
Here is the error:
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 (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
And here is my code:
// retrievedCounters is an NSMutableDictionary - (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView { // only want one section return 1; } - (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section { // get the current count and add one for the "add" cell return retrievedCounters.count + 1; } - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { UICollectionViewCell *cell; // check whether the index path is at the very end and add the appropriate cell if (indexPath.row == retrievedCounters.count) { cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"AddCounter" forIndexPath:indexPath]; } else { cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CounterCell" forIndexPath:indexPath]; } return cell; } - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { [collectionView deselectItemAtIndexPath:indexPath animated:YES]; // insert new counter at index path [self.collectionView insertItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:retrievedCounters.count-1 inSection:0]]]; }
Thank you to anyone who can help!
原文:https://stackoverflow.com/questions/20412624
最满意答案
不,这是不可能的。 您无法从suitelet访问用户事件脚本中的字段,但可以在suitelet中使用javascript事件处理程序。
No it's not possible. You can't access fields in user event script from suitelet but you can use javascript event handlers in suitelet.
相关问答
更多-
人们确实采取这种方式。 其他选择包括: 在目标字段上使用过滤来限制下拉选项 如果这是用于项目选择,请使用自定义子列表来管理显示的项目 如果以上两项工作都不是我通常所做的就是隐藏表单上的自然下拉菜单并添加我可以更好地控制的自定义下拉列表。 然后在客户端脚本中,我从自定义下拉列表中进行更改并将其应用于隐藏字段。 两种情况: 如果您在加载表单时知道下拉内容,则可以将列表创建为表单上的新选择字段,并将其填充到加载前用户事件脚本中。 如果您需要对表单上选择的其他内容做出反应,并且Netsuite的内置源代码不起作用, ...
-
因此,在postSourcing事件中,您有两个参数:type是更改的子列表的内部id,name是更改的字段的内部id。 所以在你上面粘贴的代码中: function postSourcing(type, name){ if(name == 'item'){ 只有当项子选单中的“项目”字段发生更改时,才会触发此代码。 您有两种选择:将单价和单位成本字段添加到'if'语句中 if(name == 'item' || name == 'lastpurchaseprice' || name == 'rate') ...
-
这在NetSuite帮助中明确提到 - 此记录仅可在服务器SuiteScript中编写脚本。 不支持用户事件。 希望这会有所帮助。 This is clearly mentioned in NetSuite help that - This record is scriptable in server SuiteScript only. The user events are not supported. Hope this will help.
-
您是否在发布剧本时选择了观众? 如果没有选定观众,脚本将不会执行。 偶然发生在我身上。 Did you select an audience when you released the script? If there is no audience selected, the script won't execute. Happened to me a couple of times.
-
我的错误,我误解了xedit如何处理nlapiGetNewRecord() 。 在xedit中调用nlapiGetNewRecord只返回已编辑的字段,而不是整个记录。 因此,if语句在xedit模式下永远不会成立,因为数量或状态都是null(用户不太可能同时编辑两者,并且验证依赖于这两个字段的值)。 我编辑了代码以查找字段值,如果它不在新记录中。 现在一切都按预期工作! 谢谢大家的帮助! 作为参考,更正后的代码如下。 function beforeSubmit(type){ if (type == ...
-
不,这是不可能的。 您无法从suitelet访问用户事件脚本中的字段,但可以在suitelet中使用javascript事件处理程序。 No it's not possible. You can't access fields in user event script from suitelet but you can use javascript event handlers in suitelet.
-
Netsuite用户事件脚本:并非所有的用户事件类型都会触发(Netsuite User Event Script: Not all user event types firing)[2024-01-13]
代码看起来不错。 检查部署并查看事件类型是否设置为仅创建。 The code looks good. Check the deployment and see if the event type is set to create only. -
如果转到“自定义”>“脚本”>“脚本记录”,则选择部署脚本的记录。 在该页面中,您可以设置用户事件脚本的执行顺序。 If you go to the Customization > Scripting > Scripted Records then select the record where the scripts are deployed. In that page, you can set the order of execution of your user event scripts.
-
我认为你最好的选择是创建一个帮助函数,将记录类型映射到匹配的权限。 你必须手动维护它。 看起来你正在使用SS2.0,所以假设你有可用的N /记录模块(或类似的东西),你可以这样做: function getPermissionName(recordType) { var objectPermissionMap = { customer: 'LIST_CUSTJOB', invoice: 'TRAN_CUSTINVC' }; return object ...
-
这张表格在哪里? 只有在您登录系统时才能使用上下文,因此这不适用于在线客户表单,这些表单被认为是“在系统之外”。 如果仅检索值,则可以编写Suitelet以从外部表单检索数据。 我使用此功能在外部着陆页上获取广告系列信息。 function getCamData(request, response){ if ( request.getMethod() == 'GET' ){ response.setHeader('Custom-Header-CamID', 'CamID'); var cam ...