我有一个简单的添加到购物车视图控制器。它包含您要订购的产品,并在用户添加其他产品时更新产品列表,因此我使用viewWillAppear
。我使用表视图来存储产品列表
我有子总价标签。该值来自所有产品价格总和
但是当我移动到另一个viewController
并返回添加到购物车视图控制器时,价格再次汇总。
答案 0 :(得分:0)
我通过在viewWillAppear
之前将值更改回0来解决它所以我有像这样计算子总数的功能
--BULK INSERT tempNames.dbo.tempNames
--FROM 'C:\Users\Pruthvi\Videos\file.txt'
--WITH
-- (
-- ROWTERMINATOR ='\n'
--)
USE [master]
GO
DECLARE @NameCursor as CURSOR;
DECLARE @NAME AS NVARCHAR(50);
DECLARE @NAME2 AS NVARCHAR(50);
DECLARE @NIUNT AS NVARCHAR(50);
SET @NIUNT ='niunt.niu.edu\';
SET @NameCursor = CURSOR FOR
SELECT id
FROM test.dbo.Sheet1$
OPEN @NameCursor;
FETCH NEXT FROM @NameCursor INTO @Name;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Name
set @name2 ='create database '+@Name + ';'
exec (@name2)
BEGIN
SET NOCOUNT ON
DECLARE @SQL NVARCHAR(4000);
-- SET @SQL = 'CREATE LOGIN ' + @NIUNT+ + @NAME + ' from windows';
SET @SQL = 'CREATE LOGIN' +@name+ 'WITH PASSWORD' +@name+ ';'
exec(@SQL);
--EXEC sys.sp_addsrvrolemember @loginame = @name, @rolename = N'sysadmin';
--SET @SQL = 'ALTER LOGIN ' + @name + ' DISABLE';
--EXECUTE(@SQL);
END;
FETCH NEXT FROM @NameCursor INTO @Name;
END
GO
并在我的viewWillAppear
中func theTotal(){
subTotal = 0 //here
grandTotal = 0 //here
for i in 0 ..< cartMenu.count {
let isiDishes = cartMenu[i]
subTotal += isiDishes.price
subTotalLabel.text = "Rp. \(subTotal)"
hargaAwal = subTotal
}
grandTotal = subTotal + tax + deliveryFee
grandTotalLabel.text = "Rp. \(grandTotal)"
}
我重置了子总值,因此在开始时公式也会重置。并且值子总计正在计算回来,就像没有发生一样
答案 1 :(得分:0)
将代码块移动到viewDidLoad方法。然后,每次出现视图时,该代码块都不会调用。它仅在视图加载时调用