changing views

I am trying a little ios project for the first time. So I apologize for asking the trivial.

I have two views (I copied and pasted ‘view1’ and the new views name was view11)
Each has a button with a single action:
button in view1: >>View1.pushto(View11)<<
button in view11: >>View11.pushto(View1)<<

The goal is that the buttons result in the other view being displayed.

I get the following error:

Expected a value of type class iOSView bt found a static reference to class View1.view1<<
and

Static reference to instance method: call this on an instance of class iOSView<<

But aren’t view1 and 2 instances of class iOS View?

Nope they are not implicit instances,
You need:

Var myView As New View11
View1.PushTo(myView) //if View1 is currently visible

http://documentation.xojo.com/api/deprecated/iosview.html#iosview-pushto

or

Var myView As New View11
App.CurrentScreen.Content = MyView
// this will not show the back button

http://documentation.xojo.com/api/deprecated/iosapplication.html#iosapplication-currentscreen

Hi Derk, thanks for you patience. I noted indeed that a view has no events like ‘open’ ‘close’ etc. Those are the events that I use to manipulate windows in the desktop-XOJO.
So when I have view1 then it is a class? It doesn’t show in the inspector.
Anyway, apart from my conceptual problems I have still the same/similar error message when using exactly the syntax from you and the manual. This code is all there is in View1.button1 action:

Var myView As New View11
View1.PushTo(myView) //if View1 is currently visible

and that code should be executed when I press the button1 in the View1 screen. But the compiler objects.
Errors:

  • Var myView as New View11, line 1 Syntax error Var myView = New View11
  • View11.PushTo(myView), line2, This item does not exist
  • View1.PushTo(myView), line 2. Parameter NewView expects iOSView but the is type int32

I really hope this is not something weird in may XOJO. Is there a discussion on the conceptual background somewhere in the documentation? Why are windows in the desktop so different from views for instance. Or is there a an example where i can check how switching screens is done.

View and windows are classes. You use instance of them.
For Windows on desktop you can call them directly and doing so you create an implicit instance (but you can avoid this with a flag, it’s implicit instance in the window inspector)

On iOS you define your view (for example a class named view11 with super iosView)
to navigate from another view to this one you have to:
create the istance
Navigate to the new instance

or in code
Var myView as new view11
self.pushTo(myView)

or simply
self.pushTo(new view11)

Views are stacked one over the other (that’s the meaning of push) and in this way they are really different from windows in desktop.
On iOS you can interact only with a view .

Pushing the new view on your stack will let you interact with the new view, an if you have defined it with a navigation bar visible, you will have a back button. If you press the back button the current view is popped from the stack and you can interact with the original view (and the popped one will be destroyed)

You can test this easly even with only a view

Say you edit in new project the view1 a button with this code in it’s action event:
self.pushTo(new view1)

and in the view’s open event:
Static n As Integer
n=n+1
button1.Caption=n.ToText

enable the navigation bar in view1

Run the app

you will see a button with a 1
press it you will see a button with a 2 and a back button

and so on. And you can’t go back from the first one.

Xojo for iOS can have its limitations, but for this basic stuff works very well.

Thanks Antonio,
Interestingly the self.PushTo(New View11) compiles wo errors and works. So now I have two views each with a button that selects the other view.
I observe that this switching can be repeated, So I assume if you repeat this switching, more and more copies of the View are created and are shifted to the stack.
OK my conceptual problems are dissolving a bit. Thanks

You are using lower version than Xojo R2 then use “Dim” instead of “Var”.

If you do

Dim myView As New View1

You have an instance (loaded in memory) of View1 that is named myView. The scope (life time) of myView is the action event but a reference remains if you do

SomeViewInstance.PushTo(myView)

. It’s basicly stacked on top of SomeViewInstance. When in the myView code somewhere you call

Self.Close

the instance is removed from memory and becomes unloaded from memory.

It’s best to use the examples to learn. Also look on github for “iosdesignextentions” by @Jeremie Leroy which shows how declares work and also how to call views.

I can now change Views but still it seems that a reference to objects like buttons on these views are difficult. I think I have still conceptual problems.

So I have two views, View1 and View2. Both have a text-area (called ‘FromServerTA’) that I want the same information on that I get from a PageReceived event of httpsocket.
The code in the PageReceived is simply

Dim buffer As Text = TextEncoding.UTF8.ConvertDataToText(Content)
View1(currentview).FromServerTA.text= buffer
View2(currentview).FromServerTA.text= buffer

This generates only an error (during compilation) for the last line: Type View2,View2 has no member “FroServerTA.text”
No error for the identical line before where i would expect the same error for View1.

So I am still struggling with what the difference is between Views and Windows in the DT version.
One can refer to any object on any window from everywhere in DT XOJO.

I also tried to create instances of view and view2; so:
Var MyView1 as New View1
Var MyView2 as New View2

MyView1.FromServerTA.text= buffer
MyView2.FromServerTA.text= buffer
This gives no error but the textareas are not filled with buffer

Please help me.
Dick