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

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.

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

Passing data from one view controller to another without using Segue

I have a UITableView (let’s say class “Parent” which is in view "screen 1"). When I click on one of the Parent’s cell's, I’m displaying another UITableView (let’s call it class “child” in view “Screen2”). Parent and child are connected through “segue” and I’m able to pass the data using “segue”.
For example, parent is having cell – “Cell1” and on touch “Cell1”, I’m getting “Cell11”,”Cell12”,”Cell13” [this is “screen2, table view object”].
Now, there are some descriptions associated with “Cell11” (Once I touched “Cell11”) and i'd like it to display Cell11’s description in another view controller (“screen3”). Here, to pass information between “screen2” to “screen3” I'd rather not to use a “Segue”.
How can I do this?
There are two ways in which you can present a new screen.
1) with the interface builder, here you use a segue to pass something onto the new screen.
2) manually instantiating it, after it is instantiated you can just present it.
Considering you do not want to use method 1, you can use method two like this:
ScreenBClass *screenB = [self.storyboard instantiateViewControllerWithIdentifier:#"screenB"];
screenB.objectPointerInOtherClass = self.objectIWantToPass;
[self screenB animated:YES];

Eclipse RCP - Programmatically setting a view to not be closeable

I'm trying to create an RCP view that is not closeable. I need a way to set this property programmatically because I'm creating views with secondary IDs in in the code. I can't do it through the extension editor dialogs because of this.
Is there a way to remove the x from a view programmatically?
I was finally able to figure this out.
In your perspective's createInitialLayout() function you can get the layout of the view and set its closeable property:
IViewLayout vLayout = layout.getViewLayout(View.ID);
vLayout.setCloseable(false);
This will work for views with secondary ids too. The code would be exactly the same in that case, because it will apply the closeable property to all secondary views that share the same primary id.
I've found that the following won't work:
IViewLayout vLayout = layout.getViewLayout(View.ID + ":1");
vLayout.setCloseable(false);
So you can't make individual views closeable based on their secondary ids. Either the whole group is or isn't.
You can do it easily.
Just set the closable property of view to False.
IViewLayout layout= layout.getViewLayout(View.ID);
layout.setCloseable(false);

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).

UISearchBar + UITableView +UINavigationController issue

This is a followup to this question:
UINavigationController + UITableView + UISearchBar + UISplitViewController
Is there any way to make it so the solution above doesn't make it unfilter the results? In my case you see the entire list pop back up (during the animation) when you deactivate the search in viewWillDisappear, and if you do it in viewDidDisappear then it seems to be too late and the next view is once again below/ontop of the bar. Any other solution?
OK, I've got your answer-
Here are the steps that worked for me [containing some pseudocode]:
1) Since you are searching you are most certainly already overriding ShouldReloadForSearch- So just add piece of code that saves/stores the forSeachString.
2) This one may vary quite a bit depending on your app- but the gist for this step is that you need to clear out the stored search string [set to null] if no search results are loaded. I did this in my UITableViewSource. I have 2 constructors- one for the full dataset and another on for the filtered [search results] dataset. So I just set it to null in my full dataset constructor. Yeah, you could do it differently no doubt but that's how I did it.
3) Next, do as the original "answer" states and call SetActive - [self.searchDisplayController setActive:NO];. They advocated doing it in override of ViewDidAppear. I didn't do that... I did this immediately after I pushed the next UIViewController in my RowSelected override.
4) Last, within your UIViewController that has the UISearchDisplayController attached- check for your saved search string and if it exists then do the following: 1) call SetActive again BUT this time with a true parameter ie setActive:YES... then 2) set the searchBar text to your saved search string value. I did this in the ViewWillAppear override.
Long story short... this worked for me AND it maintains the search results. Setting the searchBar text in step 4 is the key... this effectively gets the filter to persist.
Hope this helps someone
I ended up fixing this by changing where the search bar showed up (instead of going over the navigation bar, its tied to the table like in the email inbox). This fixed the issue and made it look more like the Apple apps.