Interference between two UIStepper controls - uistepper

I have a program with two stepper controls. I click the first control and increase to 10. When I click the second control, the value of the first control changes to 11, before the second control changes. If I would set the second stepper to 5 and press the first stepper down, the second value changes to 4, before the first stepper changes.
So the two steppers interferes with each other in the change from one to the other but only then.
Here is what I believe is the significant code:
#IBAction func firstMarkdownPressed(_ sender1: UIStepper) {
let firstMarkdownNum = Double(sender1.value)
firstMarkdownText.text = "\(String(format:"%.0f%",firstMarkdownNum))%"
}
#IBAction func secondMarkdownPressed(_ sender2: UIStepper) {
let secondMarkdownNum = Double(sender2.value)
secondMarkdownText.text = "\(String(format:"%.0f%",secondMarkdownNum))%"
}
override func viewDidLoad() {
super.viewDidLoad()
firstMarkdownStepper.wraps = false
firstMarkdownStepper.autorepeat = true
firstMarkdownStepper.maximumValue = 100
firstMarkdownStepper.value = 0
firstMarkdownStepper.isContinuous = false
secondMarkdownStepper.wraps = false
secondMarkdownStepper.autorepeat = true
secondMarkdownStepper.maximumValue = 100
secondMarkdownStepper.value = 0
}
Any thoughts?

Sorry I didn't check the app on an actual device. The problem I described only happens using the simulator. When running on an actual iPhone, it works as it should.

Related

How to increase JSON perameter COUNT value for pagination in swift

from backend count start form 0. and 0,1,2,3...... . For each count 10 product is showing
I have taken initially count = 0 like below
var currentCount: Int = 0
and added count perameter in JSON like below in service call: but here always shows only 10 products in collectionview... even if there are more products then also not showing.. why?
fileprivate func serviceCall(){
self.currentCount+=0
let param = ["jsonrpc": "2.0",
"params": ["type" : type, "count": currentCount]] as [String : Any]
APIReqeustManager.sharedInstance.serviceCall(param: param, vc: self, url: getUrl(of: .productByFeature), header: header) {(responseData) in
if self.currentCount > 0 {
self.viewmoreDB?.result?.products! += ViewMoreBase(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())?.result?.products ?? [ViewMoreProducts]()
}
else{
self.viewmoreDB = ViewMoreBase(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())
}
self.productsData = self.viewmoreDB?.result?.products
self.collectionView.reloadData()
}
}
and trying to use pagination like below at the end of the collectionview activity indicator is showing but if there are more products then also not loading
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == collectionView{
if (scrollView.contentOffset.y + scrollView.frame.size.height) == scrollView.contentSize.height {
serviceCall()
}
}
}
please do help
It could be any of may issues. One of the possible things is that you do not update currentCount when you get the data and your statement if self.currentCount > 0 always fails and the else part executes which means that data is not added but overwritten and you again have just one page of data.
If this is true you are probably missing currentCount = self.productsData.count or even better, you should simply make your currentCount as a computed property doing
var currentCount: Int { productsData?.count ?? 0 }
Since this is a guess a more appropriate answer is that you need to improve your skills when debugging. One of the widely used feature which is available in most modern IDEs is using breakpoints. In most IDEs you simply click left of the line you wish to put your breakpoint and an icon shows there. When your code executes with debugger it will stop at a breakpoint and you will be able to see all the information that is currently in the stack and you will be able to execute line by line to see what is going on. So in your case you could place a breakpoint at a first line after serviceCall and see which path the code takes you and why.
If using Xcode there is another feature that you can use WHILE stopped on breakpoint. You can use console on your bottom right of your IDE to print out values as chunks of code. So while stopped there you could enter "po self.currentCount" and you could see the count. More interesting would be to see things like "ViewMoreBase(dictionary: responseData.dict as NSDictionary? ?? NSDictionary())?.result?.products" to check if you get any products from the backend.

How would I go about making input type color effect my canvas on code pen?

I'm trying to get
<input type="color" class="color1" id="color2"></div>
give an output of the chosen color, here:
let clothColors = [OutputNeedsToBeHere]
Currently, I have to Manually change the colors myself, by changing and adding color values
["Color","Color","Color"]
etc. I'm making a Tearing Cloth project for school and I want to make it have as much Customization as Possible.
currently this function changes the color via a Button accessing it via
onclick="colorChange()"
function colorChange() {
cc += 1
pattern = false
if (cc >= clothColors.length) {cc = 0}
}
Now how would I get cc to become to output of the Color Input, so that I can simply choose a color on the
Input type="color"
and then click Ok and force it to change the color of the cloth manually to EXACTLY what I chose.
So Far I've tried making a Color-Wheel, and I guess my chrome version doesnt support them, or my Codepen Project is such a mess that it wont correctly activate, I also tried making an input text box that would change the color based on what you typed, (a Hex, RGBA, or Color). None of those worked, I did ask questions in a similar fashion to the one I'm typing right now, but those ones never obtained Full proof answers that successfully helped my issue.
[codepen][1] My full Codepen Project
<button onclick="colorChange()">BaseColors</button><input type="color"
class="color1" id="color2"></div>
Partial Needed bits of Javascript:
cloth:
function randint(min, max) {
return Math.floor(Math.random() * max) + min
}
let accuracy = 10
let gravity = 1000
let wind = 0
let cWind = 0
let clothY = 40
let clothX = 120
let spacing = 4
let tearDist = 60
let friction = 0.99
let bounce = 0.5
let noTop = false
let thickness = 1
let clothColors = ["red", "orange", "Gold", "yellow", "lime", "green",
"blue", "purple", "black", "grey", "darkgrey", "silver", "lightgrey",
"white"]
let cc = 0
let pattern = false
Functions:
function colorChange() {
cc += 1
pattern = false
if (cc >= clothColors.length) {cc = 0}
}
In the result I can Change the Color in a button by running the Length of the Colors written in
let clothColors:
and they are applied to the Moving cloth canvas. Unfortunately the Results I WANT are for the Colors Chosen in the input to Change the Color of the Canvas, See my link to the full project below if you wish to view the full code.
https://codepen.io/SkylerSpark/pen/ELwmoa
This works
https://codepen.io/anon/pen/ebXJaV
<button onclick="colorChange()">BaseColors</button>
<input onchange="colorChange()" type="color" class="color1" id="color2"></div>
function colorChange() {
var color = document.getElementById("color2").value;
if (clothColors.indexOf(color) ==-1) {
console.log("New color",color,clothColors)
cc=clothColors.length-1; // prepare cc to be at end
clothColors.push(color); // add new color at end
}
cc += 1; // business as usual
pattern = false
if (cc >= clothColors.length) {cc = 0}
}

How to short the code to change control properties on command buttion click in ms-access vba

I have a userform with a group of command buttons with similiar properties and fuctionality. I am using these buttons to let the user keep track about his activity. So e.g. whenever user will click the "production" button the application label will say "production" mode, when the user presses "Break" button the label will change from "production" mode to "Break" mode, Similiarly I have 7-8 buttons altogether on same form. Other conditions are whichever buttons gets pressed that button should get disabled and all other buttons should get enabled, followed by next button, if pressed it should get disabled and it should enable the button which was pressed previously.
The button which has been pressed whould also change its color and should also change the previous button's color back to normal.
I understand it would be difficult to understand the scenario, please check the code below for one of my buttons and its working well.
Private Sub btn1()
Me.Label78.Caption = Me.btn1.Caption
Me.btn1.BackColor = RGB(250, 100, 100)
Me.btn1.Gradient = 12
Me.btn1.Enabled = False
Me.btn2.Enabled = True
Me.btn2.BackColor = RGB(100, 250, 100)
Me.btn2.Gradient = 12
Me.btn3.Enabled = True
Me.btn3.BackColor = RGB(100, 250, 100)
Me.btn3.Gradient = 12
End Sub
the above code works perfeclty and changes properties to 3 buttons(its sample code not the code for all 7 buttons), but I have total 7-8 button and i may add more buttons in future SO if i keep on writing this kind of code in one button for all 7-8 buttons, then it will take a lot of time and efforct.
So what is the best possible way to short this code ?
I know this is little complicated hence please ask if any more information required.
Thanks in advance !!
You can have a helper subfunction:
Private Sub SetButton(ByVal ButtonId As Long, ByVal Enabled As Boolean)
Dim BackColor As Long
If Enabled Then
BackColor = RGB(100, 250, 100)
Else
BackColor = RGB(250, 100, 100)
End If
With Me("btn" & Cstr(Id))
.Enabled = Enabled
.Gradient = 12
.BackColor = BackColor
End With
End Sub
Then call this in the OnClick event like:
For Id = 1 To 8
Select Case Id
Case 1, 2, 4, 7
SetButton Id, True
Case Else
SetButton Id, False
End Select
Next

My OCR1A is changing even when 'if' condition is not met

I'm trying to code a simple PWM servo control that uses pin 11 on the Arduino Mega 2560. This servo should turn CW (clockwise) or CCW (counterclockwise) depending on pressing and holding one of the two buttons (L and R). The problem I seem to be running into is that the variable I have set to change the OCR1A(i) is incrementing even when the 'if' statements are not true. The buttons work as I've tested using the Serial.println(PINA) to make sure. I'm really not sure where I've gone wrong. I would appreciate any help.
void setup() {
// put your setup code here, to run once:
TCCR1A |= (1<<COM1A1)|(1<<WGM11)|(1<<WGM10);
TCCR1B = 0B00001100; // set mode 7 and prescale to 256
DDRB |= (1<<PB5); // data direction register for PORTB(pwm output pin 11)
DDRA = (1<<2)|(1<<3); // Last 2 digits of PORTA are inputs
Serial.begin(9600); //initialize the serial
}
void loop() {
int i = 63;
// This value controls the duty cycle, duty(%) = OCR1A/255*100
// 63 is just a random start position
OCR1A = i;
int swL;
int swR;
swL = PINA & 0b00000001;
swR = PINA & 0b00000010;
while(i<160) {
if (swR != 0b00000001) {
i++; // increments OCR1A when button R is pressed
Serial.println(PINA); // For testing button is pressed
Serial.println(OCR1A); // debugging use
Serial.println(i); // debugging use
delay(100);
}
if(swL != 0b00000010) {
i--; // negative increments when button L is pressed
Serial.println(PINA);
Serial.println(OCR1A);
Serial.println(i);
delay(100);
}
}
}
It seems like PINA & 0b00000001 provides some value to swL. Now I am not able to find the initial value of PINA but I assume that it is another variable having binary value and so when the two values perform a Bit-wise AND they provide a different value to swL.
I suppose this is the reason why the if condition
if (swL != 0b00000001) evaluates to TRUE and it then enters the if statement.
The same happens to the other variable swR and so it also enters the if statement.
I may be wrong but have a look at the lines:
swL = PINA & 0b00000001;
swR = PINA & 0b00000010;
Thanks, it turns out I just needed an extra set of eyes. My swR and swL were swapped. with a few other changes it now works as intended. Thank you all.

Form scrolls down and loses navigation focus after changing tabs

I have a form that has 7 tabs. Not all of the tabs show, so I have a button that unhides the tab when the user selects the button. The reason for this is to control access to this tab with user security.
Everything works nicely except for the fact that when I click on the button and the tab shows, it also scrolls up for some reason. At this point, I can't even do anything to get to the tabs which have scrolled out of view, and I don't want scroll bars either. I finally had to put a 'back' button so that I could get back to the tab that has the buttons on it at which point, I need to press the arrow keys to see the tabs again.
Here is the code for the 'Spend Plan' button: an iSecLevel of 1 gets to see all of the buttons. iSecLevel of 2 only sees the Spend Plan Button
Private Sub cmdSP_Click()
Select Case iSecLevel
Case 2
Me.TAB_SP.Pages(1).Visible = True
Me.TAB_SP.Pages(1).SetFocus
Me.TAB_SP.Pages(4).Visible = True
Me.TAB_SP.Pages(2).Visible = False
Me.TAB_SP.Pages(3).Visible = False
Me.TAB_SP.Pages(5).Visible = False
Me.TAB_SP.Pages(6).Visible = False
Me.cmdCopyFromServer.Visible = False
Me.cmdCopyToServer.Visible = False
Me.cmdCOB.Visible = False
Me.TAB_SP.Pages(6).Visible = False
strFormState = "Default"
Spend_Plan_Form_Update
Case 1
Me.TAB_SP.Pages(1).Visible = True
Me.TAB_SP.Pages(1).SetFocus
Me.TAB_SP.Pages(4).Visible = True
Me.TAB_SP.Pages(2).Visible = False
Me.TAB_SP.Pages(3).Visible = False
Me.TAB_SP.Pages(5).Visible = True
Me.TAB_SP.Pages(6).Visible = True
Me.cmdCopyFromServer.Visible = True
Me.cmdCopyToServer.Visible = True
Me.cmdCOB.Visible = True
strFormState = "Default"
Spend_Plan_Form_Update
End Select
End Sub
Is it an anchor or centering problem that I am experiencing? I would prefer for all of the tabs to remain visible at the top of the screen.