- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在做一个售票的ipad应用,想减去的时候遇到了问题..
UI是这样制作的:
for(NSString *string in ticketArray){
float y = 60*ticketCount+spaceFloat;
//subView to contain one ticket
UIView *ticketTypeView = [[UIView alloc]initWithFrame:CGRectMake(10, y, 1000, 60)];
if(ticketCount%2){
ticketTypeView.backgroundColor = [UIColor lightGrayColor];
}
[self.view addSubview:ticketTypeView];
//label for ticket type name
UILabel *ticketType = [[UILabel alloc]initWithFrame:CGRectMake(10, 3, 500, 50)];
[ticketType setText:string];
[ticketType setFont:[UIFont fontWithName:@"Helvetica neue" size:20.0]];
[ticketTypeView addSubview:ticketType];
//UIStepper for ticket amount
UIStepper *stepper = [[UIStepper alloc]initWithFrame:CGRectMake(500, 16, 0, 0)];
stepper.transform = CGAffineTransformMakeScale(1.2, 1.2);
[stepper addTarget:self action:@selector(chanegestep:) forControlEvents:UIControlEventValueChanged];
stepper.maximumValue = 100;
stepper.minimumValue = 0;
[ticketTypeView addSubview:stepper];
//label for price pr. ticket
UILabel *pricePrTicket = [[UILabel alloc]initWithFrame:CGRectMake(620, 5, 100, 50)];
[pricePrTicket setText:@"1000.50"];
pricePrTicket.tag = kTagPriceTicket;
[ticketTypeView addSubview:pricePrTicket];
//totalPrice label
UILabel *totalTypePrice = [[UILabel alloc]initWithFrame:CGRectMake(900, 5, 100, 50)];
[totalTypePrice setText:@"0.00 Kr."];
totalTypePrice.tag = kTagTotalTypePrice;
[ticketTypeView addSubview:totalTypePrice];
ticketCount++;
}
我的 ValueChanged 方法:
- (IBAction) chanegestep:(UIStepper *)sender {
double va = [sender value];
NSLog(@"stepper pressed");
//get the 2 labels for the price and for displaying price
UILabel *ticketprice = (UILabel *)[sender.superview viewWithTag:kTagPriceTicket];
UILabel *totalPrice = (UILabel *)[sender.superview viewWithTag:kTagTotalTypePrice];
double price = [ticketprice.text doubleValue];
//calc the total from that one ticet type
double totalDisplayed = va*price;
//add to the complete sales amount
completeSalesAmount += totalDisplayed;
NSLog(@"%.02f",completeSalesAmount);
if(ticketprice){
totalPrice.text = [[NSString alloc]initWithFormat:@"%.02fKr.",totalDisplayed];
}
//activate btnContinue
if(completeSalesAmount!=0){
[btnContinue setEnabled:YES];
}
//[ setText:[NSString stringWithFormat:@"%d", (int)va]];
我的问题:将数字相加效果很好,但是当按下步进器上的“-”时,我必须以某种方式检测到它,并从 totalSalesAmount 中减去给定票的价格..
感谢任何帮助。
问候,即将到来的 IOS 开发者 xD
编辑:
每次调用 valueChanged 时都会计算 completedSalesAmount..
假设我有 2 种票证类型,每种票证类型有 1 个选择。
ticket1 - price 10$ - amount 1, total 10$ (10*1)
completeSalesAmount - 0 += (10*1) = 10$
ticket2 - price 10$ - amount 1, total 10$ (10*1)
completeSalesAmount - 10 += (10*1) = 20$
现在在 ticket1 上按下“-”
ticket1 - price 10$ - amount 0, total 0$ (10*0)
completeSalesAmount += 0...
最佳答案
问题是您不知道按下了步进器上的哪个按钮。你可以做的是像这篇文章建议的那样将你的 UIStepper 子类化:
UIStepper. Find out whether incremented or decremented
否则你可以创建一个函数来计算每个 UIStepper 的 completeSalesAmount
,你需要将你的 UIStepper 包装器放在一个数组中:
NSMutableArray *fullSteppers = [NSMutableArray arrayWithCapacity:[ticketArray count]];
for(NSString *string in ticketArray){
...
stepper.tag = kTagStepper;
[fullSteppers addObject:ticketTypeView];
...
}
- (void)updateCompleteSalesAmount{
completeSalesAmount = 0;
for(UIView *fullStepper in fullSteppers){
UILabel *ticketprice = (UILabel *)[fullStepper viewWithTag:kTagPriceTicket];
UILabel *totalPrice = (UILabel *)[fullStepper viewWithTag:kTagTotalTypePrice];
double price = [ticketprice.text doubleValue];
UIStepper *stepper = (UIStepper *)[fullStepper viewWithTag:kTagStepper];
completeSalesAmount += stepper.value * price;
}
}
只需在您的 changestep 方法中调用更新函数:
- (IBAction) chanegestep:(UIStepper *)sender {
....
[self updateCompleteSalesAmount];
}
关于IOS 从以编程方式制作的标签和步进器中减去,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24135771/
我有两个列表,我想从 neg 中减去列表 pos 中元素的频率。所以: neg = [x for x in all[:800000]] pos = [x for x in all[800000:]]
我有两个列表,我想从 neg 中减去列表 pos 中元素的频率。所以: neg = [x for x in all[:800000]] pos = [x for x in all[800000:]]
我正在尝试减去 2 个标准逻辑向量并得到错误 p2 <= p1(11 downto 0)- idata(11 downto 0); Error (10327): VHDL error at sub.v
我将以下代码嵌入到类中。每当我运行 distToPoint 时,它都会给出错误“不支持的操作数类型 -: 'NoneType' 和 'float'” 我不知道为什么它会返回 NoneType 和如何让
这一直让我想知道, 假设我有这种情况: select (...long sub query..) - (...long sub query..) 我想把 - 放在条件中,这意味着有时它会是 - 有时是
我有两个 vector 。我需要从 vector1 中删除 vector2 中的内容。 [编辑:不清楚这是否意味着按照下面的链接或设置差异进行逐元素减法] 我使用 Visual Studio 2010
我有一张这样的 table : id product_property_id product_id amount type 1 1 145 10
我有两个 boolean 值列表 buy_machine 和 broken_machine。我想创建第三个列表 working_machines,它是购买的机器数量的总和并减去坏机器的数量。 我尝试了
我似乎可以解决这个问题。我有两个来自 sql 的访问者/国家/地区列表 us,us,uk,fr,uk,uk,uk 和 us,uk 我用 array_count_values() 将它们制成数组: Ar
我在 javascript 中减去时间时遇到了麻烦,尽管我已经谷歌搜索了 2 天但没有任何运气:( 我正在尝试为调查问卷计时。当用户开始调查问卷时,会记录时间戳。当用户完成/单击提交时,会记录新的时间
我正在尝试对 flex 搜索中索引的字段进行一些分析。 其中两个字段是“start_time”和“end_time”。我基本上希望将这两个字段的差异分组,即('end_time'-'start_tim
我有一个函数,它接收两个 BigDecimal 数字,即 bd1 和 bd2 作为参数。该函数应减去 bd1 - db2 并返回 bd1 和 bd2 的小数位数均为 2,结果的小数位数也应仅为 2但使
根据ldt_code中的ld源代码here。没有将dl_main传递给phdr的上下文,我对为什么通过减去虚拟地址来推断main_map的加载地址有些困惑。 我跟踪过的代码: 1124 static
我进行了多次重复测量的治疗,我想减去每次治疗的每个时间点的对照值。数据集的形状是这样的,有多年、物种和处理。 ID Year Species Treatment value 1 2010 x
我正在尝试查找一次旅行的矩形区域,可以在此处找到更多上下文 我在下面的代码中遇到的错误是: "Exception in thread "main" java.lang.ArrayIndexOutOfB
我一直在尝试使用 pandas dataframe 减去我读入 python 的列之间的日期和时间。我写的代码如下: Time = df['t'] - df['t'].shift(1) + df['t
I want to subtract all values in a[nn,...,0] by b[nn] while keeping the original structure of the ar
假设我有两个列表:List l1,和 Listl2 请帮助我如何在 2 个列表之间合并、减去和相交。谢谢。 注意:我使用的是 .NET 2.0,所以我不能使用 LINQ。谢谢。 最佳答案 以下是伪代码
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我正在尝试运行以下代码: extern crate unicase; use unicase::UniCase; use std::collections::HashSet; fn main() {
我是一名优秀的程序员,十分优秀!