ON/OFF button keeps toggling through states on every touch - button

I don´t know what I´m doing wrong, maybe I'm sitting here way too long on my project. However, I set up a settings menu in my menuScene and I want to create a simple on-off button with a texture with this code:
if ([settingsMenuNode.name isEqualToString:#"checkmark1"]) {
if (self.checkmarkBanner == NO) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
self.checkmarkBanner = YES;
NSLog(#"YES");
}
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
self.checkmarkBanner = NO;
NSLog(#"NO");
}
}
every time I touch on the node, I get both logs for ON & OFF at the same time.
can anyone please help me out?
checkmarkBanner is my BOOL just to set whether a banner notification during the game appears or not.

ok, thank you for your quick answers, so i´ve updated my code to this (i added some NSUserDefaults):
//CheckMarkBanner
if ([settingsMenuNode.name isEqualToString:#"checkmarkBanner"]) {
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
NSString *offString = #"NO";
[[NSUserDefaults standardUserDefaults]setObject:offString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner NO");
}
else {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
NSString *onString = #"YES";
[[NSUserDefaults standardUserDefaults]setObject:onString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner YES");
}
}

Related

How do I turn off the Accessibility Inspector in the iOS 9 simulator?

The accessibility inspector is turned on by my KIF tests (apparently it's necessary for KIF to work.) Problem is, its window occludes controls some subsequent UI tests need to tap on and those tests fail.
How can I turn the Accessibility Inspector off when my KIF tests are done with it so my UI Tests can run?
(Turning it off "manually" from the simulator's Settings app is not a solution—I'm looking for something I can call from code, set in the target or...?)
It is not on by default. You must turn it on manually.
I saw the following on Stew Gleadow's blog.
You just need to change the line:
CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
change kCFBooleanTrue to kCFBooleanFalse.
+ (void)_enableAccessibilityInSimulator {
NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];
NSString *appSupportLocation = #"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport";
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
NSString *simulatorRoot = [environment objectForKey:#"IPHONE_SIMULATOR_ROOT"];
if (simulatorRoot) {
appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation];
}
void *appSupportLibrary = dlopen([appSupportLocation fileSystemRepresentation], RTLD_LAZY);
CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain");
if (copySharedResourcesPreferencesDomainForDomain) {
CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility"));
if (accessibilityDomain) {
CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
CFRelease(accessibilityDomain);
}
}
[autoreleasePool drain];
}

Make different lists from list

I use Qt and C++, I have a list (QList<int>)
list<<1<<3<<4<<5<<9<<22<<32<<45
I want to make this
If user enter 4 I want to make this;
list1<<1<<3<<4<<5
list2<<9<<22<<32<<45
If user enter 3, I want to divide 3 lists etc.. How can I do this?
See the code below. I have not tested it , but i might give you an idea. Remember to
#include <QtAlgorithms> too.
read x;
QVector<QList<QString> > vectorOfLists;
bool continueLoop = true;
while (continueLoop)
{
QList<QString> temp(x);
if (list.count () > x)
{
qCopy(list.begin(), list.begin()+x, temp.begin());
list.erase (list.begin(), list.begin()+x);
}
else
{
qCopy(list.begin(), list.end(), temp.begin());
continueLoop = false;
}
//Add list to collection
vectorOfLists.append (temp);
}

How to assign dataGrid to other dataGrid in Flex. a = b doesn't work

in Flex I have something like that:
var dg:DataGrid = new DataGrid();
if (something) dg = dg1 else if (something_2) dg = dg2;
dg.dataProvider.getItemAt(3).id;
and dg is ALWAYS pointing at DataGrid (even if dg1 has name DataGrid_test and dg2 = DataGrid_test2) and finally action is made on my first DataGrid (DataGrid_test).
Why?
How can I pass dg1 or dg2 to dg?
Here is pasted almost full code of this part of application. I edited it to make that more clear.
var dg:DataGrid = null;
if ( currentState == "state1" ) { //if this condition is true then app. go into if and
dg = dataGrid_first; // make dg = DataGrid (1)
test.text = "inco"; // shows "inco" in "test" label
} else if ( currentState == "state2" ) { // if this is true then app. go..
dg = dataGrid_second; //here and set dg as DataGrid (exactly!) (2)
test.text = "outgo"; // and change test label into blank text (earlier text disapears)
}
search(dg);
It is modified with advice of '#splash'
Still not working.
EDIT:
I made this sceond edit to answer for all You who are helping me with that :) I think that it will be the best way. In codeblock above I added comments. (please read now comments and after that come back here :) )
Now I will explain exactly what happens.
I debug it many times and here are results:
dg is pointing at DataGrid (as component in flex, not as my dataGrid_first), I needed to extend DataGrid so now it is ColorColumn component (I don't know if I called it properly), not DataGrid. And dg is pointing at ColorColumn not at dataGrid_first or dataGrid_second. I even tried today the same thing what suggest #splash:
if ( currentState == "state1" ) {
test.text = "inco";
search(dataGrid_first);
} else if ( currentState == "state2" ) {
test.text = "outgo";
search(dataGrid_second);
}
and search still points at ColorColumn :/ My problem is really easy- I just want to pass to search different dataGrid on each state. If You have other ideas how I can do that in right way then I will pleased to hear about it. :)
But still I don't understand why it doesn't work. My search function uses algorhitm Boyer-Moor for searching through dataGrid.dataProvider for some text. If it find something then it is pushed into new array and after passing whole dataProvider I colorize rows with searched word.
If dg is never pointing to dg1 and dg2 then your (something) expressions may be evaluate to false. Check the value of your if-conditions - this should be easy to debug.
This should work:
var dg:DataGrid = null;
if (something)
dg = dg1;
else if (something_2)
dg = dg2;
if (dg)
{
// do something with dg
}
[Update]
I still can't see why your code isn't working, but you could simplify it like this:
if ( currentState == "state1" ) {
test.text = "inco";
search(dataGrid_first);
} else if ( currentState == "state2" ) {
test.text = "outgo";
search(dataGrid_second);
}
I'd propose to write this - since I guess either dg1 or dg2 should be assigned:
if (something) {
dg = dg1;
} else {
dg = dg2;
}
There may be cases, where if () {} else () {} neither executes the first or the second conditional block.
Finally a small hint, which structurally eliminates unwanted assignments in if conditions: Always write the literal left of the comparison operation: if ( "state1" == currentState ). If you accidentally typed = instead of ==, the flex compiler emits an error. The other notation silently assigns a value.
Additionally: Did you single-stepped through your code and watched the variables dg1, dg2 and dg? If not, set a breakpoint a few line before the if-statement and run the code step by step from there on. What do you see?
Here's a another tip: Use assertions to check for inconistencies:
package my.company.utilities {
public function assert(expression:Boolean):void {
// probably conditionally compile this statement
if (!expression) {
throw new Error("Assertion failed!");
}
} // assert
}
Use it e.g. at the beginning of a method like this:
public function doTransaction( fromAccount:int, toAccount:int ) {
assert( 0 < fromAccount );
assert( 0 < toAccount );
}
A typically good use of assert is to check variables regarding their range. As of the above example, fromAccount and toAccount should always be positive. Due to a bug, bad values might get passed to doTransaction(). In this case, the assertion fires an error.

How to navigate next tab while first tab view in process?

I have 4 tabs in UITabBarcontroller. My problem is i need to navigate to next tab by user click while first tab process in on going?? how to run the process on background??
Now second tab not working while the first tab view in process. I used PerformSelectorInBackground but it's not help me?? Can any one help me Please????
Am poor in english, can you understand my problem?
Yuva.M
Run your heavy process with NSThread.
Snippet from here:
- (IBAction) startThreadButtonPressed:(UIButton *)sender {
[NSThread detachNewThreadSelector:#selector(startTheBackgroundJob) toTarget:self withObject:nil];
}
- (void)startTheBackgroundJob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
[NSThread sleepForTimeInterval:3];
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + 0.01;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
}

1050: Cannot assign to a non-reference value

Hi my code as fallows what is wrong with it?
thank you and sorry for my bad english.
protected function belgelerDG_itemClickHandler(event:ListEvent):void
{
var durum:Boolean = false;
if(belgeicerikWindow==null){
belgeicerikWindow=new belgeicerik();
belgeicerikWindow.title=belgelerDG.selectedItem.belge;
belgeicerikWindow.open();
}
else{
durum=false;
for ( var i:int = NativeApplication.nativeApplication.openedWindows.length - 1; i >= 0; --i ) {
if(NativeApplication.nativeApplication.openedWindows[i].title.toString() == belgeicerikWindow.title=belgelerDG.selectedItem.belge){
belgeicerikWindow.orderToFront();
durum=true;
}
}
if(durum==false){
belgeicerikWindow=new belgeicerik();
belgeicerikWindow.title=belgelerDG.selectedItem.belge;
belgeicerikWindow.open();
}
}
}
I'm betting the problem lies with the if statement that starts with:
if(NativeApplication.nativeApplication.openedWindows[i].title.toString()
You are doing an assignment within the value you are trying to compare against:
== belgeicerikWindow.title=belgelerDG.selectedItem.belge)
If it isn't what is causing your problem, at least it is something you should fix to make things more legible. :)

Resources