Display route.steps (swift ) - swift

I am having some problem when it comes to display the steps from MKDirections route into a UILabel. I tried get each index from the steps array using the for in loop, it only show the Arrive at destination which means that all the instructions within the loop went by so fast, therefore i am seeing the last index in the array . Can someone help me please ...

it shows "Arrive at destination" because you are cycling the whole array and the label gets only the object at the end, you are basically overwriting it over and over until the for cycle arrives to its final element

You are seeing only the last value from the array in the UILabel, though it is actually displaying all the values very, very quickly. If you just want to see each of the values in the UILabel, you could either use UITimeInterval to change the value every few seconds, or add a UIButton that would handle updating of the text on the UILabel.

Related

UIPickerView custom title

I have an array that I use to populate my pickerView, a simple string array. The issue is that I need the first item to be something like "Choose team".
The only way I have achieved that is the add the first item in the array to be "Choose team", but this messes up the array structure for me and I wonder if there is another way of doing this.
So, can I add a default value to a UIPickerValue, if no: how would you have solved this issue?
There is no easy way to add a default value. You can duplicate the array and add the string to the duplicated version for display but then you have to be careful about indexing issues. If the array's value changes programmatically, it can be a disaster. This duplication thing is not a good design anyway.
Alternatively, you can add a fixed label on right side of each picker values. Here is the example
Fixed labels in the selection bar of a UIPickerView

How can I get my program to automatically perform a carriage return when string value superseeds the screen size?

I am making a quiz game that displays questions fetched from parse. I create the label programmatically, but stumble upon some issues when the string value is too long. Is there a way to make the label automatically print on a new line when it goes beyond the screen width?
I figured this out. I decided to make the frame a bit bigger and add in lines using the label.numberOfLines function. Now it returns perfectly.

Swift UI Test Static Text Value

I have a label that gets its text assigned after a certain action happens, and I want to test that the text it has been assigned is correct with a UI test.
I am getting the XCUIElement with
.descendantsMatchingType(.StaticText).elementBoundByIndex(UInt(3))
The element is a staticText, and the element.value is not returning anything useful, and I'm unable to find another way of getting any sort of useful value from the staticText, besides the debugDescription. However, it says in the docs that the debugDescription is unreliable and should not be used for the actual tests.
How can I verify that this label has the correct text?
This has been answered with a recent update to XCUIElement; there is now a label property that gets the text from a .StaticText element.

Unity/NGUI Updating List at runtime

I was wondering if someone could explain to me how I update a list at runtime in Unity?
For example I have a spell book, which has 3 spells in it, when I drag them to my action bar they get re-parented to it, what I'm trying to do is get a list of each child under the actionbar transform,
My problem is where to actually do something like this if I try something like below in the update, it adds whatever's there many times, which I can understand since update runs every frame..
list = actionbarui.GetComponent(UIGrid).GetChildList();
for(var i =0;i < list.size; i++)
{
buttonList.Add(list[i].gameObject);
}
If I add a callback to the buttons so that whenever they're drag and dropped it runs the above code and add thing's additively, as in, if you drag just one "spell" on it will loop through once, which is fine, but as soon as you add another it loops through three times, that is, it already has one it then adds the same one again PLUS the new button that's just been dragged on for a total of 3.
I've tried changing the code to
list = actionbarui.GetComponent(UIGrid).GetChildList();
for each(var child : Transform in list.GetEnumerator())
{
buttonList.Add(child.gameObject);
}
But this simple doesn't add anything, I am unsure how to go about keep the lists update as they are dragged off and on, could anyone please explain how this is achieved?
Please ignore the second "list" code, it's implementing "BetterLists" as apart of NGUI, so doesn't follow standard list methods.
Thank you for reading
If I add a callback to the buttons so that whenever they're drag and dropped it runs the above code and add thing's additively, as in, if you drag just one "spell" on it will loop through once, which is fine, but as soon as you add another it loops through three times, that is, it already has one it then adds the same one again PLUS the new button that's just been dragged on for a total of 3.
That is the expected result here. You are running through the list of children and adding them to your buttonlist, so first time there is only one item to add, then when you add another child there are two items to add, thus resulting in three items.
Either don't have a for loop and do:
buttonList.Add(the_GameObject_that_was_just_added_to_the_bar);
Or clear your buttonList before the for loop:
list = actionbarui.GetComponent(UIGrid).GetChildList();
buttonList.Clear();
for(var i =0;i < list.size; i++)
{
buttonList.Add(list[i].gameObject);
}
Alternatively to Dover8's response, you can first check if the buttonList already contains a reference to the child to be added. If it does, continue. Otherwise add the new child.
However, given the expense of doing the checks, and since you are already looping through the list already, I'd recommend that you follow his suggestion to clear the list before running the loop. It will probably give you the best performance out of these examples.
If there's a reason you can't or shouldn't clear the buttonList, and you still need to run through it, I'd recommend my suggestion. It really depends on which implementation works best for what you are trying to do. The point is that there are several ways to do this, and they have different performance profiles you need to consider.

UISearchbar results showing inconsistently in table view

I am using a real-time search against an external API (XML) based on what the user is entering in the search bar..
I am using a case-insensitive search. The thing was working fine, until I moved the code or rather added a thread. Suddenly the results that I get are a bit consistent. They are not incorrect, but they are sometimes lesser in number.
e.g. if a user enters "a", it will show around 7 results, say AAR, Aaron, Staar,Mtaar ...
Then if enters "aa" , it will show 1 result (AAR), then if he enters "aar", it will show 3 results AAR, Star, Mtaar
Again if backspace is pressed and if the current term in the search bar is aa, it will now show 3 results...
Another example, if I type "goog", it displays nothing in the table cell results (even though i see that it has parsed Google), while if i add an "l", i.e. if the term is now "googl", it now shows Google in the cell below.
I am updating my table view immediately after the parsing is complete.
So basically after I added thread, the search results have got a bit inconsistent. I am not sure why.
Note that in all cases the results shown are all correct, but just the no. of them is varying.
Could someone please help me with the issue.
Thanks a lot.
can you provide some sample code how you access your filtered table content array? You can NSLog() the result you get from the API and compare with the ones are displayed in your tableView.