How to query the child views of a parent view using Titanium? - iphone

I am looking to create a general purpose routine that will operate over a view's children. Within the routine I need to be able to iterate over the child views. I don't see anything in the API that would suggest that there is any way to get the child views. There is an "add()" and a "remove()" method but nothing like "get()" nor does there appear to be any properties like "views". What am I missing?

this is the basic structure for removing child objects from a view
if (view.children) {
for (var c = view.children.length - 1; c >= 0; c--) {
view.remove(view.children[c]);
}
}

i would check also for
if (view.children[c] !== undefined) {..}
since i already got problems with android without verifieing.

Related

How to retrieve view from controller of another view?

I am just wondering how can I get one of the UI5 views in an application.
I know there is a method:
sap.ui.jsview(); // in case the view is written in JavaScript
But the problem with this method is: if you assign ID for any of the controls and you have already inflated this view, you get an error.
So I want to know how to check if the view already exists and then if yes return that existing view, otherwise create the view with the corresponding API such as the above one.
I also know in the control for view I can go
this.getView();
But as I said, how to get this view from another view?
I am not quite understanding your question
With managed object id's are unique, so if you try and create the same view twice you will get an error.
when you create your view the easiest way to access it is via an Id
sap.ui.jsview("view1",'testapp.view.view1');
sap.ui.getCore().byId('view1');
NB. views should not talk to anyone other than their controller A terrific Model View Controller (MVC) diagram
sap.ui.getCore().byId(<id_of_the_view>)
Where <id_of_the_view> can be obtained in the following way:
suppose that the corresponding controller of <id_of_the_view> is "controllerA.js",
then you can console.log, inside controllerA.js,
console.log(this.getView())
This will print you an object which contains the id of such view. This will be <id_of_the_view>
I think here is one solution.
Make a global variable;
Use it to create element.
In First View:
var mytextField ;(use it as global)
mytextField = new sap.ui.commons.TextField('textfieldId');
In Second View:
var myValue = mytextField .getValue();
~Mansi Rao

Xcode: he first view doesn't see changes made by the second one

I'm a very newbie in the obj-c programming and have some troubles trying to change values between two views. I'm using Xcode 4.5 and storyboards and I've some problems with passing a changed value from the second view to the first one.
Here's my 2 very simple views (posting the link as I'm a new user and can't post images):
https://www.dropbox.com/s/q4o2bblu1p57zod/img.png
These views are assigned to the same class (ViewController) and the code I'm using to change the 2 labels is:
-(IBAction)setLabel:(id)sender
{
if (myTextField.text.length != 0) {
myLabel1.text = myTextField.text;
myLabel2.text = myTextField.text;
}
}
The problem is that Label1 changes correctly its text, but there's nothing to do with Label2! It doesn't want to change...
I think I'm trying to do something that can be made in others ways...Can you please tell me if it's correct?
You need to use Protocol-Delegate approach to update content in First view.
I suggest you to visit this sample link.
Your two view controllers may be of the same class but they are going to be different objects at runtime. You have a segue between them and when that executes a new instance will be created. Since the 'label2' of the second instance is not displayed on its screen, your assignment doesn't produce a visible change.

Zend frame work multiple view from single action

Can anyone tell me how can i make more then one view through single action.
actually I have a controller action fetching data from model but I have to show data in 2 different views (half data in 1st and rest in 2nd)
I know it is possible.
Can any one explain how it will be implemented.
I'm not entirely sure whether you mean having two different views depending on a condition or two views at the same time.
From the action you can use:
$this->renderScript( 'views/page.phtml' );
and you can use multiple renderScripts and they will stack up and render in the order that they are called. Or you can have a condition separating them.
if($blah)
{
$this->renderScript( 'views/page.phtml' );
return;
}
else
{
$this->renderScript( 'views/page.phtml' );
return;
}
Is this the sort of thing you mean?
Just use the render method of the controller action to display the view you want.
Refer to Rendering Views in the Zend reference manual for more information (you could also use Named Segments if needed/applicable).

How do I obtain information about the pages in a UIScrollView?

I have a run of about 10 different methods, they all pass "page" and "index" between them in order to define a ScrollView with multiple pages. The majority of these methods run within a loop (for each page).
I'm working on a way to re-orient and re-position the pages depending on the device orientation. My trouble now is trying to get access to these multiple pages so I can run a method re-orienting them. Is there a way to loop through the pages and access their information (size, frame, contentSize etc.) so I can then just manipulate them?
You could put a pointer for each view into an array. Then iterating through the array config the Views like this:
-(void)configScrollViewForOriantation:(UIInterfaceOrientation)interfaceOrientation
//do an if on the oriantation and supply 2 versions...
//eg..
if(UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
CGRect f;
for (UIViewController *page in pageArray) {
f = page.frame;
f.size.width = ..;
f.origin.x = ....;
page.contentSize = CGSizeMake(newWidth,newHeight)
//etc
}
else{
//landscape config
}
}
NB. If you called this method in a CAAffine animation it would animate the changes too.
Ideally you should only make one for loop and set some constants for the configs you are going to do based on the orientation.
Create a class that knows about the model data, and can divide it up into numbered pages. Now pass that object between your methods, instead of the raw page/index values. Now extend that object to work with your other orientation.

Zend Navigation: current page

There is a method isActive() in Zend_Navigation. But it returns true for all the elements in the current path
(parent li is active and all the children too, even when the current is parent li).
Is there any method like isCurrent(), to determine whether the current menu item is the current page?
I just like to add custom class attribute to just one, current element in the whole nested tree of ul's and li's.
easier with:
$activeElement = $view->navigation()->findOneBy('active', 1);
if you're inside your view script you can use:
$activeElement = $this->navigation()->findOneBy('active', 1);
You will need to use your own navigation view script, but that's fairly simple. Then try:
$this->navigation()->findActive($this->yourNavContainer);
That will return an object, var dump it and you will see the data you need. I think the variable is simply called 'page'. Do this before you build your menu, pre/post dispatch, then in your viewscript, do an if statement to check this var against the current looped item (i guess your loop it in a foreach).