Velocity : Breaking out of foreach-loop dynamically - velocity

i need to implement a solution in Velocity for breaking out of a foreach-loop at the forelast item of the array. With the API i came to build this, but i doesnt break out and still shows all rows of the loop.
Does anyone have a better or working approach for me?
«#if($special)»
«#foreach($item in $sum)»
«#if($foreach.hasNext==false)» «#break» «#end»
«do special stuff»
«#end»
«#else»
«#foreach($item in $sum)»
«do normal stuff»
«#end»
«#end»

#if(!$foreach.hasNext) #break #end
or
#if($foreach.hasNext == false) #break #end
should both work for Velocity 1.7+. If you have some doubt about it, you can display
$foreach.hasNext
in the loop and check that it prints true true true ... false.
For prior versions of Velocity, you would have to do it yourself:
#set($count = $num.size())
#foreach($item in $num)
#if($velocityCount < $count)
...
#end
#end
Note that the $velocityCount variable (which was deprecated in 1.7 and disappeared in 2.0) starts at 1.

Related

XCode track variable (SKNode.paused)

I am programming a game on XCode's SpriteKit. I have a variable NodeGamePlay (an SKNode) and I set it to NodeGamePlay.paused=true when I hit a pause button. I have tracked this through various NSLog statements scattered throughout my code and when I set NodeGamePlay.paused=true, the game actually pauses, but it seems to somewhat arbitrarily unpause itself (I don't even have a NodeGamePlay.paused=false anywhere in the code).
Anyways, I have not had any success tracking down when this is getting changed incorrectly to paused=false. I tried using the "watch variable" feature, to watch the variable NodeGamePlay, but the debug won't stop/alert me that NodeGamePlay switches between true & false. I was wondering if there is some method of tracking THIS property and having the debug stop as soon as the value is changed?
Setting .paused == TRUE on children nodes in Sprite Kit produces some odd behavior in my experience, at least in iOS 7, because when a parent node has its .paused set to FALSE, it sets all of its child nodes .paused to FALSE, etc.
So it creates a scenario where you need to override setPaused on your NodeGamePlay class to check a different flag to see if it should allow .paused to be set to FALSE when its parent calls it.
-(void)setPaused:(BOOL)paused
{
if (paused == NO && self.iAmAllowedToUnPauseWhenParentTellsMe == NO) {
return;
}
[super setPaused:paused];
}

How can I make an SLTextField tappable?

I have been writing a test with "Subliminal's" "SLTextField" and have run into some really annoying issues lately.
I have written a test which should update a text field, clear it, and update it again.
For some reason when I use "SLTextField" to change the element text I consistently receive errors stating that "SLTextFields" aren't tappable elements. Is this true? If so, what is the point of having an "SLTextField" class at all?
I can rewrite the same test code to find the element as an "SLElement", at which point I can tap the element, open up a keyboard object and type the necessary text, but it seems like I'm circumventing the entire functionality of Subliminal in doing this.
What's wrong w/"SLTextField"?
Code:
SLTextField *textField = [SLTextField elementWithAccessibilityLabel:fieldName];
SLWaitUntilTrue([textField isTappable], DEFAULT_TIMEOUT);
textField.text = newValue;
The above code throws an error, stating that "textField" never becomes tappable. Alternatively, the code below works perfectly, though it's unnecessarily verbose and seems to make "SLTextField" superfluous.
Code:
SLElement *field = [SLElement elementWithAccessibilityLabel:fieldName];
[field tapAtActivationPoint];
//fill with text
SLKeyboard *kb = [SLKeyboard keyboard];
SLKeyboardKey *deleteKey = [SLKeyboardKey elementWithAccessibilityLabel:#"Delete"];
while(![field.value isEqualToString:#""]){
[deleteKey touchAndHoldWithDuration:1.2];
}
[kb typeString:newValue];
SLKeyboardKey *doneKey = [SLKeyboardKey elementWithAccessibilityLabel:#"Next"];
if(![doneKey isValid]){
doneKey = [SLKeyboardKey elementWithAccessibilityLabel:#"Done"];
}
[doneKey tap];
[kb hide];
Is your TextField within a TableViewCell? And are you seeing this on iOS 7?
If so, it might have been fixed by https://github.com/inkling/Subliminal/pull/202 (merged 6/6/2014).

How do I dynamically change the height of a TableViewRow?

Application Type: mobile
Titanium SDK: 3.1.0.GA
Platform & version: iOS 6.1
Device: iOS Simulator
Host Operating System: OSX 10.8.3
Titanium Studio: 3.1.0.201304151600
I'd like to conditionally show/hide a textfield in a TableViewRow. In order to do this I need to expand the height of the row. The following code doesn't work, though. The TableViewRow is actually an Alloy controller. I first tried animating it before I realized that it can't be animated. Now I'm just trying to change the height and that isn't even working. I've tried using the setHeight method along with just setting the height property directly to no avail.
Any ideas?
var notesVisible = false;
function notes_click() {
if(notesVisible == false) {
Ti.API.info('expanding');
$.row.height = 200;
// $.notes_container.setHeight(124);
notesVisible = true;
} else {
Ti.API.info('contracting');
$.row.height = 75;
$.notes_container.setHeight(0);
notesVisible = false;
}
};
There are two good ways of doing this, both should be done from the click event listener.
Method 1) One way is to directly change the "height" variable of the row
Method 2) The second is to create a new row and replace the current row with the new row
Method 1 is more straightforward but I found it to be glitchy depending on what version of the SDK you are using, but with 3.1.0 it should work. Both methods should be called from the 'click' eventListener as its easier to tell Titanium which row to act on based on the click
So here is an example
currentTableview.addEventListener('click',function(e)
{
// DO whatever your row is supposed to do when clicked
// Now lets change the height of the row to a new height, 200 in this example
e.row.height = 200
}
With Method two, it involves creating a new row and then replacing the current row with this call
currentTableview.updateRow(e.index,newlyCreatedUpdatedRow);
I know its an old question asked by some one but the solution provided will not work and i think best solution for this is by making a recursive function and changes the height of your row and need to play with the visibility of views inside that row hopefully will help someone :)

is it possible to move object between 2 `UICollectionView`

i'm working with UICollectionView, I have 2 collection. and I need to move object from the first one to the second by dragging.
my project is based on LXReorderableCollectionViewFlowLayout.
Is it possible to move object between 2 UICollectionView by dragging?
Yes! (with a caveat)
You need to replace the delegate method willMoveToIndexPath and make a few modifications:
- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout itemAtIndexPath:(NSIndexPath *)theFromIndexPath willMoveToIndexPath:(NSIndexPath *)theToIndexPath
{
/* code removed from example code
id theFromItem = [self.deck objectAtIndex:theFromIndexPath.item];
[self.deck removeObjectAtIndex:theFromIndexPath.item];
[self.deck insertObject:theFromItem atIndex:theToIndexPath.item];
*/
NSLog(#"From: %d %d To: %d %d", theFromIndexPath.section, theFromIndexPath.row, theToIndexPath.section, theToIndexPath.row);
NSMutableArray *fromSectionArray = mySectionArray[theFromIndexPath.section];
NSMutableArray *toSectionArray = mySectionArray[theToIndexPath.section];
id theFromItem = fromSectionArray.myItemArray[theFromIndexPath.item];
[fromSectionArray.myItemsArray removeObjectAtIndex:theFromIndexPath.item];
[toSectionArray.myItemsArray insertObject:theFromItem atIndex:theToIndexPath.item];
}
I'm just writing the code here (it might have errors) but I think you get the gist of what I'm doing. I'm just adding one layer for section and not assuming that the "from" and "to" items come from the same section.
The caveat:
This code works but I'm having problems if the section is initially empty of items.
Hope this helps.

Animating the NSLevelIndicator when the values change

Currently I have the following code to update the NSLevelindicator:
[self.headerIndicator selfFloatValue:heightValue]
Is there any way to animate the the level indicator between values when they update?
read this answer to animating sliders. i haven't tried it with level indicators but from the API docs it seems a viable option. the source code there can easily be adapt: NSSlider animation
I have tried this code and it works fine:
Swift:
self.CpuLevel.maxValue = Double(value)
If [[[self.headerIndicator] animator] setFloatValue:heightValue]; doesn't work, you must add the capability yourself. See NSAnimatablePropertyContainer.
You could write your own method, something like this to change the level. The math in there tries to keep the total "animation" time equal regardless of how big the transition is from the old value to the new (around 1 second with these values).
-(void)updateLevel:(NSNumber *) newLevelNum {
float currentLevel = self.level.floatValue;
float newLevel = newLevelNum.floatValue;
if (self.delay == 0.0) // self.delay is a float property set to 0.0 elsewhere
self.delay = .2 /(newLevel - currentLevel);
[self.level setFloatValue:currentLevel + .2];
if (self.level.floatValue - newLevel < .01){
[self performSelector:#selector(updateLevel:) withObject:newLevelNum afterDelay:self.delay];
}
}