Accessing MT.Dialog Elements

classic Classic list List threaded Threaded
9 messages Options
Iki
Reply | Threaded
Open this post in threaded view
|

Accessing MT.Dialog Elements

Iki
Hi guys/gals,

I'm having trouble accessing MonoTouch Dialog elements. 

Example is: 

I have a list of items from which i create StringElements in section. After elements is tapped, i would like to go to a new view, on which i would, based on the element tapped filled out the data. 

StringElement.Tapped is without parameters,

se.Tapped += () => 
                {


                };

 and i can't find a proper way to send reference of the object that is tapped.

I'm currently using DialogViewControllers, for my main view, on which i create list of name, and on my detail view which i need to fill up with data based on element from the main view.

I did try with this

public void RowSelected (UITableView tableViewNSIndexPath indexPath)
{
    DetailViewController dvc = new DetailViewController (names [indexPath.Row]);
    this.NavigationController.PushViewController (dvctrue);
}

But I don't see any effect. 

Thanks!



_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Juan M Gómez
Hi Iki,
There are a few ways to go on:
->Just a specialized class of StringElement that exposes your properties or a new event.
->If you assign the data in the same struct, just use it (if it is a loop, remember to set a new assign in the block of lambda)

cheers


Juan M Gómez


2013/3/5 Iki <[hidden email]>
Hi guys/gals,

I'm having trouble accessing MonoTouch Dialog elements. 

Example is: 

I have a list of items from which i create StringElements in section. After elements is tapped, i would like to go to a new view, on which i would, based on the element tapped filled out the data. 

StringElement.Tapped is without parameters,

se.Tapped += () => 
                {


                };

 and i can't find a proper way to send reference of the object that is tapped.

I'm currently using DialogViewControllers, for my main view, on which i create list of name, and on my detail view which i need to fill up with data based on element from the main view.

I did try with this

public void RowSelected (UITableView tableViewNSIndexPath indexPath)
{
    DetailViewController dvc = new DetailViewController (names [indexPath.Row]);
    this.NavigationController.PushViewController (dvctrue);
}

But I don't see any effect. 

Thanks!



_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch



_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Iki
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Iki
Hey Juan,

Thanks for such quick response, as a matter of fact, my approach was exactly like Your second solution.
But along the way I have made a mistake while assigning a new DialogViewController, here is the example of working solution:

public partial class MainViewController : DialogViewController
{
    List<stringnewsList;
    List<StringElementstringElementsList;

    public MainViewController () : base (UITableViewStyle.Groupednull)
    {

       Root = new RootElement ("Main View") {};
       Section section = new Section ("");


        newsList = new List<string>()
        {
            "News - 1"
           ,"News - 2"
           ,"News - 3"
           ,"News - 4"
         };

         stringElementsList = new List<StringElement> (){};

         for (int i = 0i < newsList.Counti++) 
         {
            StringElement se = new StringElement(newsList[i]);
            section.Add(se);

            se.Tapped += () => 
            {
               //DialogViewController with modified ctor (string name)
                 DetailViewController dvc = new DetailViewController(newsList[se.IndexPath.Row]);
                 this.NavigationController.PushViewController(dvc,true);
             };

             stringElementsList.Add(se);
          }

          Root.Add (section);
    

     }
}



On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:

Hi Iki,
There are a few ways to go on:
->Just a specialized class of StringElement that exposes your properties or a new event.
->If you assign the data in the same struct, just use it (if it is a loop, remember to set a new assign in the block of lambda)

cheers


Juan M Gómez


2013/3/5 Iki <[hidden email]>
Hi guys/gals,

I'm having trouble accessing MonoTouch Dialog elements. 

Example is: 

I have a list of items from which i create StringElements in section. After elements is tapped, i would like to go to a new view, on which i would, based on the element tapped filled out the data. 

StringElement.Tapped is without parameters,

se.Tapped += () => 
                {


                };

 and i can't find a proper way to send reference of the object that is tapped.

I'm currently using DialogViewControllers, for my main view, on which i create list of name, and on my detail view which i need to fill up with data based on element from the main view.

I did try with this

public void RowSelected (UITableView tableViewNSIndexPath indexPath)
{
    DetailViewController dvc = new DetailViewController (names [indexPath.Row]);
    this.NavigationController.PushViewController (dvctrue);
}

But I don't see any effect. 

Thanks!



_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Nic Wise
Hi Iki

for (int i = 0; i < newsList.Count; i++)
         {
            StringElement se = new StringElement(newsList[i]);
            section.Add(se);

            int localCounter = i; //grab it, 'cos you want to use it
inside the lamda, and "i" may have the wrong scope
            se.Tapped += () =>
            {
               //DialogViewController with modified ctor (string name)
                 DetailViewController dvc = new
DetailViewController(newsList[localCounter]); //use the local one
                 this.NavigationController.PushViewController(dvc,true);
             };

             stringElementsList.Add(se); //you dont need this, you are
storing it in the section above!
          }

you might not need the localCounter bit (you might just be able to use
i) - try it out. If it always shows the last element, regardless, then
use the localCounter bit. I know you need to do this for objects, just
not 100% sure on value types :)

you could rewrite it like this, too:



newsList = new List<string>()
        {
            "News - 1"
           ,"News - 2"
           ,"News - 3"
           ,"News - 4"
         };

foreach(var s in newsList)
{

string temp = s; //capture outside, use inside the lambda/delegate

section.Add(new StringElement(s, () => {
  DetailViewController dvc = new DetailViewController(temp);
   this.NavigationController.PushViewController(dvc,true);
});


}




On 5 March 2013 20:37, Iki <[hidden email]> wrote:

> Hey Juan,
>
> Thanks for such quick response, as a matter of fact, my approach was exactly
> like Your second solution.
> But along the way I have made a mistake while assigning a new
> DialogViewController, here is the example of working solution:
>
> public partial class MainViewController : DialogViewController
> {
>     List<string> newsList;
>     List<StringElement> stringElementsList;
>
>     public MainViewController () : base (UITableViewStyle.Grouped, null)
>     {
>
>        Root = new RootElement ("Main View") {};
>        Section section = new Section ("");
>
>
>         newsList = new List<string>()
>         {
>             "News - 1"
>            ,"News - 2"
>            ,"News - 3"
>            ,"News - 4"
>          };
>
>          stringElementsList = new List<StringElement> (){};
>
>          for (int i = 0; i < newsList.Count; i++)
>          {
>             StringElement se = new StringElement(newsList[i]);
>             section.Add(se);
>
>             se.Tapped += () =>
>             {
>                //DialogViewController with modified ctor (string name)
>                  DetailViewController dvc = new
> DetailViewController(newsList[se.IndexPath.Row]);
>                  this.NavigationController.PushViewController(dvc,true);
>              };
>
>              stringElementsList.Add(se);
>           }
>
>           Root.Add (section);
>
>
>      }
> }
>
>
>
> On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>
> Hi Iki,
> There are a few ways to go on:
> ->Just a specialized class of StringElement that exposes your properties or
> a new event.
> ->If you assign the data in the same struct, just use it (if it is a loop,
> remember to set a new assign in the block of lambda)
>
> cheers
>
>
> Juan M Gómez
>
>
> 2013/3/5 Iki <[hidden email]>
>>
>> Hi guys/gals,
>>
>> I'm having trouble accessing MonoTouch Dialog elements.
>>
>> Example is:
>>
>> I have a list of items from which i create StringElements in section.
>> After elements is tapped, i would like to go to a new view, on which i
>> would, based on the element tapped filled out the data.
>>
>> StringElement.Tapped is without parameters,
>>
>> se.Tapped += () =>
>>                 {
>>
>>
>>                 };
>>
>>  and i can't find a proper way to send reference of the object that is
>> tapped.
>>
>> I'm currently using DialogViewControllers, for my main view, on which i
>> create list of name, and on my detail view which i need to fill up with data
>> based on element from the main view.
>>
>> I did try with this
>>
>> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>> {
>>     DetailViewController dvc = new DetailViewController (names
>> [indexPath.Row]);
>>     this.NavigationController.PushViewController (dvc, true);
>> }
>>
>> But I don't see any effect.
>>
>> Thanks!
>>
>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
>
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Juan M Gómez
Yes, it's clousure stuff. If you want you can see why that happens here: http://www.defmacro.org/ramblings/fp.html#part_11 although I recommend the whole article for everybody, it's pretty nice.



2013/3/5 Nic Wise <[hidden email]>
Hi Iki

for (int i = 0; i < newsList.Count; i++)
         {
            StringElement se = new StringElement(newsList[i]);
            section.Add(se);

            int localCounter = i; //grab it, 'cos you want to use it
inside the lamda, and "i" may have the wrong scope
            se.Tapped += () =>
            {
               //DialogViewController with modified ctor (string name)
                 DetailViewController dvc = new
DetailViewController(newsList[localCounter]); //use the local one
                 this.NavigationController.PushViewController(dvc,true);
             };

             stringElementsList.Add(se); //you dont need this, you are
storing it in the section above!
          }

you might not need the localCounter bit (you might just be able to use
i) - try it out. If it always shows the last element, regardless, then
use the localCounter bit. I know you need to do this for objects, just
not 100% sure on value types :)

you could rewrite it like this, too:



newsList = new List<string>()
        {
            "News - 1"
           ,"News - 2"
           ,"News - 3"
           ,"News - 4"
         };

foreach(var s in newsList)
{

string temp = s; //capture outside, use inside the lambda/delegate

section.Add(new StringElement(s, () => {
  DetailViewController dvc = new DetailViewController(temp);
   this.NavigationController.PushViewController(dvc,true);
});


}




On 5 March 2013 20:37, Iki <[hidden email]> wrote:
> Hey Juan,
>
> Thanks for such quick response, as a matter of fact, my approach was exactly
> like Your second solution.
> But along the way I have made a mistake while assigning a new
> DialogViewController, here is the example of working solution:
>
> public partial class MainViewController : DialogViewController
> {
>     List<string> newsList;
>     List<StringElement> stringElementsList;
>
>     public MainViewController () : base (UITableViewStyle.Grouped, null)
>     {
>
>        Root = new RootElement ("Main View") {};
>        Section section = new Section ("");
>
>
>         newsList = new List<string>()
>         {
>             "News - 1"
>            ,"News - 2"
>            ,"News - 3"
>            ,"News - 4"
>          };
>
>          stringElementsList = new List<StringElement> (){};
>
>          for (int i = 0; i < newsList.Count; i++)
>          {
>             StringElement se = new StringElement(newsList[i]);
>             section.Add(se);
>
>             se.Tapped += () =>
>             {
>                //DialogViewController with modified ctor (string name)
>                  DetailViewController dvc = new
> DetailViewController(newsList[se.IndexPath.Row]);
>                  this.NavigationController.PushViewController(dvc,true);
>              };
>
>              stringElementsList.Add(se);
>           }
>
>           Root.Add (section);
>
>
>      }
> }
>
>
>
> On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>
> Hi Iki,
> There are a few ways to go on:
> ->Just a specialized class of StringElement that exposes your properties or
> a new event.
> ->If you assign the data in the same struct, just use it (if it is a loop,
> remember to set a new assign in the block of lambda)
>
> cheers
>
>
> Juan M Gómez
>
>
> 2013/3/5 Iki <[hidden email]>
>>
>> Hi guys/gals,
>>
>> I'm having trouble accessing MonoTouch Dialog elements.
>>
>> Example is:
>>
>> I have a list of items from which i create StringElements in section.
>> After elements is tapped, i would like to go to a new view, on which i
>> would, based on the element tapped filled out the data.
>>
>> StringElement.Tapped is without parameters,
>>
>> se.Tapped += () =>
>>                 {
>>
>>
>>                 };
>>
>>  and i can't find a proper way to send reference of the object that is
>> tapped.
>>
>> I'm currently using DialogViewControllers, for my main view, on which i
>> create list of name, and on my detail view which i need to fill up with data
>> based on element from the main view.
>>
>> I did try with this
>>
>> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>> {
>>     DetailViewController dvc = new DetailViewController (names
>> [indexPath.Row]);
>>     this.NavigationController.PushViewController (dvc, true);
>> }
>>
>> But I don't see any effect.
>>
>> Thanks!
>>
>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
>
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



--
Nic Wise
t.  <a href="tel:%2B44%207788%20592%20806" value="+447788592806">+44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Nic Wise
Thanks. Instapapered.

Need to learn F#, too :)

On 5 March 2013 21:54, Juan M Gómez <[hidden email]> wrote:

> Yes, it's clousure stuff. If you want you can see why that happens here:
> http://www.defmacro.org/ramblings/fp.html#part_11 although I recommend the
> whole article for everybody, it's pretty nice.
>
>
>
>
> 2013/3/5 Nic Wise <[hidden email]>
>>
>> Hi Iki
>>
>> for (int i = 0; i < newsList.Count; i++)
>>          {
>>             StringElement se = new StringElement(newsList[i]);
>>             section.Add(se);
>>
>>             int localCounter = i; //grab it, 'cos you want to use it
>> inside the lamda, and "i" may have the wrong scope
>>             se.Tapped += () =>
>>             {
>>                //DialogViewController with modified ctor (string name)
>>                  DetailViewController dvc = new
>> DetailViewController(newsList[localCounter]); //use the local one
>>                  this.NavigationController.PushViewController(dvc,true);
>>              };
>>
>>              stringElementsList.Add(se); //you dont need this, you are
>> storing it in the section above!
>>           }
>>
>> you might not need the localCounter bit (you might just be able to use
>> i) - try it out. If it always shows the last element, regardless, then
>> use the localCounter bit. I know you need to do this for objects, just
>> not 100% sure on value types :)
>>
>> you could rewrite it like this, too:
>>
>>
>>
>> newsList = new List<string>()
>>         {
>>             "News - 1"
>>            ,"News - 2"
>>            ,"News - 3"
>>            ,"News - 4"
>>          };
>>
>> foreach(var s in newsList)
>> {
>>
>> string temp = s; //capture outside, use inside the lambda/delegate
>>
>> section.Add(new StringElement(s, () => {
>>   DetailViewController dvc = new DetailViewController(temp);
>>    this.NavigationController.PushViewController(dvc,true);
>> });
>>
>>
>> }
>>
>>
>>
>>
>> On 5 March 2013 20:37, Iki <[hidden email]> wrote:
>> > Hey Juan,
>> >
>> > Thanks for such quick response, as a matter of fact, my approach was
>> > exactly
>> > like Your second solution.
>> > But along the way I have made a mistake while assigning a new
>> > DialogViewController, here is the example of working solution:
>> >
>> > public partial class MainViewController : DialogViewController
>> > {
>> >     List<string> newsList;
>> >     List<StringElement> stringElementsList;
>> >
>> >     public MainViewController () : base (UITableViewStyle.Grouped, null)
>> >     {
>> >
>> >        Root = new RootElement ("Main View") {};
>> >        Section section = new Section ("");
>> >
>> >
>> >         newsList = new List<string>()
>> >         {
>> >             "News - 1"
>> >            ,"News - 2"
>> >            ,"News - 3"
>> >            ,"News - 4"
>> >          };
>> >
>> >          stringElementsList = new List<StringElement> (){};
>> >
>> >          for (int i = 0; i < newsList.Count; i++)
>> >          {
>> >             StringElement se = new StringElement(newsList[i]);
>> >             section.Add(se);
>> >
>> >             se.Tapped += () =>
>> >             {
>> >                //DialogViewController with modified ctor (string name)
>> >                  DetailViewController dvc = new
>> > DetailViewController(newsList[se.IndexPath.Row]);
>> >                  this.NavigationController.PushViewController(dvc,true);
>> >              };
>> >
>> >              stringElementsList.Add(se);
>> >           }
>> >
>> >           Root.Add (section);
>> >
>> >
>> >      }
>> > }
>> >
>> >
>> >
>> > On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>> >
>> > Hi Iki,
>> > There are a few ways to go on:
>> > ->Just a specialized class of StringElement that exposes your properties
>> > or
>> > a new event.
>> > ->If you assign the data in the same struct, just use it (if it is a
>> > loop,
>> > remember to set a new assign in the block of lambda)
>> >
>> > cheers
>> >
>> >
>> > Juan M Gómez
>> >
>> >
>> > 2013/3/5 Iki <[hidden email]>
>> >>
>> >> Hi guys/gals,
>> >>
>> >> I'm having trouble accessing MonoTouch Dialog elements.
>> >>
>> >> Example is:
>> >>
>> >> I have a list of items from which i create StringElements in section.
>> >> After elements is tapped, i would like to go to a new view, on which i
>> >> would, based on the element tapped filled out the data.
>> >>
>> >> StringElement.Tapped is without parameters,
>> >>
>> >> se.Tapped += () =>
>> >>                 {
>> >>
>> >>
>> >>                 };
>> >>
>> >>  and i can't find a proper way to send reference of the object that is
>> >> tapped.
>> >>
>> >> I'm currently using DialogViewControllers, for my main view, on which i
>> >> create list of name, and on my detail view which i need to fill up with
>> >> data
>> >> based on element from the main view.
>> >>
>> >> I did try with this
>> >>
>> >> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>> >> {
>> >>     DetailViewController dvc = new DetailViewController (names
>> >> [indexPath.Row]);
>> >>     this.NavigationController.PushViewController (dvc, true);
>> >> }
>> >>
>> >> But I don't see any effect.
>> >>
>> >> Thanks!
>> >>
>> >>
>> >>
>> >> _______________________________________________
>> >> MonoTouch mailing list
>> >> [hidden email]
>> >> http://lists.ximian.com/mailman/listinfo/monotouch
>> >>
>> >
>> > _______________________________________________
>> > MonoTouch mailing list
>> > [hidden email]
>> > http://lists.ximian.com/mailman/listinfo/monotouch
>> >
>> >
>> >
>> > _______________________________________________
>> > MonoTouch mailing list
>> > [hidden email]
>> > http://lists.ximian.com/mailman/listinfo/monotouch
>> >
>>
>>
>>
>> --
>> Nic Wise
>> t.  +44 7788 592 806 | @fastchicken
>> b. http://www.fastchicken.co.nz/
>
>
>
> _______________________________________________
> MonoTouch mailing list
> [hidden email]
> http://lists.ximian.com/mailman/listinfo/monotouch
>



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Nic Wise
(I ment _I_ need to learn F#)

On 5 March 2013 22:35, Nic Wise <[hidden email]> wrote:

> Thanks. Instapapered.
>
> Need to learn F#, too :)
>
> On 5 March 2013 21:54, Juan M Gómez <[hidden email]> wrote:
>> Yes, it's clousure stuff. If you want you can see why that happens here:
>> http://www.defmacro.org/ramblings/fp.html#part_11 although I recommend the
>> whole article for everybody, it's pretty nice.
>>
>>
>>
>>
>> 2013/3/5 Nic Wise <[hidden email]>
>>>
>>> Hi Iki
>>>
>>> for (int i = 0; i < newsList.Count; i++)
>>>          {
>>>             StringElement se = new StringElement(newsList[i]);
>>>             section.Add(se);
>>>
>>>             int localCounter = i; //grab it, 'cos you want to use it
>>> inside the lamda, and "i" may have the wrong scope
>>>             se.Tapped += () =>
>>>             {
>>>                //DialogViewController with modified ctor (string name)
>>>                  DetailViewController dvc = new
>>> DetailViewController(newsList[localCounter]); //use the local one
>>>                  this.NavigationController.PushViewController(dvc,true);
>>>              };
>>>
>>>              stringElementsList.Add(se); //you dont need this, you are
>>> storing it in the section above!
>>>           }
>>>
>>> you might not need the localCounter bit (you might just be able to use
>>> i) - try it out. If it always shows the last element, regardless, then
>>> use the localCounter bit. I know you need to do this for objects, just
>>> not 100% sure on value types :)
>>>
>>> you could rewrite it like this, too:
>>>
>>>
>>>
>>> newsList = new List<string>()
>>>         {
>>>             "News - 1"
>>>            ,"News - 2"
>>>            ,"News - 3"
>>>            ,"News - 4"
>>>          };
>>>
>>> foreach(var s in newsList)
>>> {
>>>
>>> string temp = s; //capture outside, use inside the lambda/delegate
>>>
>>> section.Add(new StringElement(s, () => {
>>>   DetailViewController dvc = new DetailViewController(temp);
>>>    this.NavigationController.PushViewController(dvc,true);
>>> });
>>>
>>>
>>> }
>>>
>>>
>>>
>>>
>>> On 5 March 2013 20:37, Iki <[hidden email]> wrote:
>>> > Hey Juan,
>>> >
>>> > Thanks for such quick response, as a matter of fact, my approach was
>>> > exactly
>>> > like Your second solution.
>>> > But along the way I have made a mistake while assigning a new
>>> > DialogViewController, here is the example of working solution:
>>> >
>>> > public partial class MainViewController : DialogViewController
>>> > {
>>> >     List<string> newsList;
>>> >     List<StringElement> stringElementsList;
>>> >
>>> >     public MainViewController () : base (UITableViewStyle.Grouped, null)
>>> >     {
>>> >
>>> >        Root = new RootElement ("Main View") {};
>>> >        Section section = new Section ("");
>>> >
>>> >
>>> >         newsList = new List<string>()
>>> >         {
>>> >             "News - 1"
>>> >            ,"News - 2"
>>> >            ,"News - 3"
>>> >            ,"News - 4"
>>> >          };
>>> >
>>> >          stringElementsList = new List<StringElement> (){};
>>> >
>>> >          for (int i = 0; i < newsList.Count; i++)
>>> >          {
>>> >             StringElement se = new StringElement(newsList[i]);
>>> >             section.Add(se);
>>> >
>>> >             se.Tapped += () =>
>>> >             {
>>> >                //DialogViewController with modified ctor (string name)
>>> >                  DetailViewController dvc = new
>>> > DetailViewController(newsList[se.IndexPath.Row]);
>>> >                  this.NavigationController.PushViewController(dvc,true);
>>> >              };
>>> >
>>> >              stringElementsList.Add(se);
>>> >           }
>>> >
>>> >           Root.Add (section);
>>> >
>>> >
>>> >      }
>>> > }
>>> >
>>> >
>>> >
>>> > On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>>> >
>>> > Hi Iki,
>>> > There are a few ways to go on:
>>> > ->Just a specialized class of StringElement that exposes your properties
>>> > or
>>> > a new event.
>>> > ->If you assign the data in the same struct, just use it (if it is a
>>> > loop,
>>> > remember to set a new assign in the block of lambda)
>>> >
>>> > cheers
>>> >
>>> >
>>> > Juan M Gómez
>>> >
>>> >
>>> > 2013/3/5 Iki <[hidden email]>
>>> >>
>>> >> Hi guys/gals,
>>> >>
>>> >> I'm having trouble accessing MonoTouch Dialog elements.
>>> >>
>>> >> Example is:
>>> >>
>>> >> I have a list of items from which i create StringElements in section.
>>> >> After elements is tapped, i would like to go to a new view, on which i
>>> >> would, based on the element tapped filled out the data.
>>> >>
>>> >> StringElement.Tapped is without parameters,
>>> >>
>>> >> se.Tapped += () =>
>>> >>                 {
>>> >>
>>> >>
>>> >>                 };
>>> >>
>>> >>  and i can't find a proper way to send reference of the object that is
>>> >> tapped.
>>> >>
>>> >> I'm currently using DialogViewControllers, for my main view, on which i
>>> >> create list of name, and on my detail view which i need to fill up with
>>> >> data
>>> >> based on element from the main view.
>>> >>
>>> >> I did try with this
>>> >>
>>> >> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>>> >> {
>>> >>     DetailViewController dvc = new DetailViewController (names
>>> >> [indexPath.Row]);
>>> >>     this.NavigationController.PushViewController (dvc, true);
>>> >> }
>>> >>
>>> >> But I don't see any effect.
>>> >>
>>> >> Thanks!
>>> >>
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> MonoTouch mailing list
>>> >> [hidden email]
>>> >> http://lists.ximian.com/mailman/listinfo/monotouch
>>> >>
>>> >
>>> > _______________________________________________
>>> > MonoTouch mailing list
>>> > [hidden email]
>>> > http://lists.ximian.com/mailman/listinfo/monotouch
>>> >
>>> >
>>> >
>>> > _______________________________________________
>>> > MonoTouch mailing list
>>> > [hidden email]
>>> > http://lists.ximian.com/mailman/listinfo/monotouch
>>> >
>>>
>>>
>>>
>>> --
>>> Nic Wise
>>> t.  +44 7788 592 806 | @fastchicken
>>> b. http://www.fastchicken.co.nz/
>>
>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
>
>
> --
> Nic Wise
> t.  +44 7788 592 806 | @fastchicken
> b. http://www.fastchicken.co.nz/



--
Nic Wise
t.  +44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Juan M Gómez
I'm looking for time to deep into F#. It Seems that Xamarin.iOS/Android could have full support soon, just in time :D



2013/3/5 Nic Wise <[hidden email]>
(I ment _I_ need to learn F#)

On 5 March 2013 22:35, Nic Wise <[hidden email]> wrote:
> Thanks. Instapapered.
>
> Need to learn F#, too :)
>
> On 5 March 2013 21:54, Juan M Gómez <[hidden email]> wrote:
>> Yes, it's clousure stuff. If you want you can see why that happens here:
>> http://www.defmacro.org/ramblings/fp.html#part_11 although I recommend the
>> whole article for everybody, it's pretty nice.
>>
>>
>>
>>
>> 2013/3/5 Nic Wise <[hidden email]>
>>>
>>> Hi Iki
>>>
>>> for (int i = 0; i < newsList.Count; i++)
>>>          {
>>>             StringElement se = new StringElement(newsList[i]);
>>>             section.Add(se);
>>>
>>>             int localCounter = i; //grab it, 'cos you want to use it
>>> inside the lamda, and "i" may have the wrong scope
>>>             se.Tapped += () =>
>>>             {
>>>                //DialogViewController with modified ctor (string name)
>>>                  DetailViewController dvc = new
>>> DetailViewController(newsList[localCounter]); //use the local one
>>>                  this.NavigationController.PushViewController(dvc,true);
>>>              };
>>>
>>>              stringElementsList.Add(se); //you dont need this, you are
>>> storing it in the section above!
>>>           }
>>>
>>> you might not need the localCounter bit (you might just be able to use
>>> i) - try it out. If it always shows the last element, regardless, then
>>> use the localCounter bit. I know you need to do this for objects, just
>>> not 100% sure on value types :)
>>>
>>> you could rewrite it like this, too:
>>>
>>>
>>>
>>> newsList = new List<string>()
>>>         {
>>>             "News - 1"
>>>            ,"News - 2"
>>>            ,"News - 3"
>>>            ,"News - 4"
>>>          };
>>>
>>> foreach(var s in newsList)
>>> {
>>>
>>> string temp = s; //capture outside, use inside the lambda/delegate
>>>
>>> section.Add(new StringElement(s, () => {
>>>   DetailViewController dvc = new DetailViewController(temp);
>>>    this.NavigationController.PushViewController(dvc,true);
>>> });
>>>
>>>
>>> }
>>>
>>>
>>>
>>>
>>> On 5 March 2013 20:37, Iki <[hidden email]> wrote:
>>> > Hey Juan,
>>> >
>>> > Thanks for such quick response, as a matter of fact, my approach was
>>> > exactly
>>> > like Your second solution.
>>> > But along the way I have made a mistake while assigning a new
>>> > DialogViewController, here is the example of working solution:
>>> >
>>> > public partial class MainViewController : DialogViewController
>>> > {
>>> >     List<string> newsList;
>>> >     List<StringElement> stringElementsList;
>>> >
>>> >     public MainViewController () : base (UITableViewStyle.Grouped, null)
>>> >     {
>>> >
>>> >        Root = new RootElement ("Main View") {};
>>> >        Section section = new Section ("");
>>> >
>>> >
>>> >         newsList = new List<string>()
>>> >         {
>>> >             "News - 1"
>>> >            ,"News - 2"
>>> >            ,"News - 3"
>>> >            ,"News - 4"
>>> >          };
>>> >
>>> >          stringElementsList = new List<StringElement> (){};
>>> >
>>> >          for (int i = 0; i < newsList.Count; i++)
>>> >          {
>>> >             StringElement se = new StringElement(newsList[i]);
>>> >             section.Add(se);
>>> >
>>> >             se.Tapped += () =>
>>> >             {
>>> >                //DialogViewController with modified ctor (string name)
>>> >                  DetailViewController dvc = new
>>> > DetailViewController(newsList[se.IndexPath.Row]);
>>> >                  this.NavigationController.PushViewController(dvc,true);
>>> >              };
>>> >
>>> >              stringElementsList.Add(se);
>>> >           }
>>> >
>>> >           Root.Add (section);
>>> >
>>> >
>>> >      }
>>> > }
>>> >
>>> >
>>> >
>>> > On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>>> >
>>> > Hi Iki,
>>> > There are a few ways to go on:
>>> > ->Just a specialized class of StringElement that exposes your properties
>>> > or
>>> > a new event.
>>> > ->If you assign the data in the same struct, just use it (if it is a
>>> > loop,
>>> > remember to set a new assign in the block of lambda)
>>> >
>>> > cheers
>>> >
>>> >
>>> > Juan M Gómez
>>> >
>>> >
>>> > 2013/3/5 Iki <[hidden email]>
>>> >>
>>> >> Hi guys/gals,
>>> >>
>>> >> I'm having trouble accessing MonoTouch Dialog elements.
>>> >>
>>> >> Example is:
>>> >>
>>> >> I have a list of items from which i create StringElements in section.
>>> >> After elements is tapped, i would like to go to a new view, on which i
>>> >> would, based on the element tapped filled out the data.
>>> >>
>>> >> StringElement.Tapped is without parameters,
>>> >>
>>> >> se.Tapped += () =>
>>> >>                 {
>>> >>
>>> >>
>>> >>                 };
>>> >>
>>> >>  and i can't find a proper way to send reference of the object that is
>>> >> tapped.
>>> >>
>>> >> I'm currently using DialogViewControllers, for my main view, on which i
>>> >> create list of name, and on my detail view which i need to fill up with
>>> >> data
>>> >> based on element from the main view.
>>> >>
>>> >> I did try with this
>>> >>
>>> >> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>>> >> {
>>> >>     DetailViewController dvc = new DetailViewController (names
>>> >> [indexPath.Row]);
>>> >>     this.NavigationController.PushViewController (dvc, true);
>>> >> }
>>> >>
>>> >> But I don't see any effect.
>>> >>
>>> >> Thanks!
>>> >>
>>> >>
>>> >>
>>> >> _______________________________________________
>>> >> MonoTouch mailing list
>>> >> [hidden email]
>>> >> http://lists.ximian.com/mailman/listinfo/monotouch
>>> >>
>>> >
>>> > _______________________________________________
>>> > MonoTouch mailing list
>>> > [hidden email]
>>> > http://lists.ximian.com/mailman/listinfo/monotouch
>>> >
>>> >
>>> >
>>> > _______________________________________________
>>> > MonoTouch mailing list
>>> > [hidden email]
>>> > http://lists.ximian.com/mailman/listinfo/monotouch
>>> >
>>>
>>>
>>>
>>> --
>>> Nic Wise
>>> t.  <a href="tel:%2B44%207788%20592%20806" value="+447788592806">+44 7788 592 806 | @fastchicken
>>> b. http://www.fastchicken.co.nz/
>>
>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
>
>
> --
> Nic Wise
> t.  <a href="tel:%2B44%207788%20592%20806" value="+447788592806">+44 7788 592 806 | @fastchicken
> b. http://www.fastchicken.co.nz/



--
Nic Wise
t.  <a href="tel:%2B44%207788%20592%20806" value="+447788592806">+44 7788 592 806 | @fastchicken
b. http://www.fastchicken.co.nz/


_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Iki
Reply | Threaded
Open this post in threaded view
|

Re: Accessing MT.Dialog Elements

Iki
In reply to this post by Nic Wise
Hi Nick :)

I'm using "foreach" version inside my project, in the example here I was testing out what happens with my code, because as you said, i had a problem with always showing the latest element :D

Thx for help!

 
On Mar 5, 2013, at 10:31 PM, Nic Wise <[hidden email]> wrote:

> Hi Iki
>
> for (int i = 0; i < newsList.Count; i++)
>         {
>            StringElement se = new StringElement(newsList[i]);
>            section.Add(se);
>
>            int localCounter = i; //grab it, 'cos you want to use it
> inside the lamda, and "i" may have the wrong scope
>            se.Tapped += () =>
>            {
>               //DialogViewController with modified ctor (string name)
>                 DetailViewController dvc = new
> DetailViewController(newsList[localCounter]); //use the local one
>                 this.NavigationController.PushViewController(dvc,true);
>             };
>
>             stringElementsList.Add(se); //you dont need this, you are
> storing it in the section above!
>          }
>
> you might not need the localCounter bit (you might just be able to use
> i) - try it out. If it always shows the last element, regardless, then
> use the localCounter bit. I know you need to do this for objects, just
> not 100% sure on value types :)
>
> you could rewrite it like this, too:
>
>
>
> newsList = new List<string>()
>        {
>            "News - 1"
>           ,"News - 2"
>           ,"News - 3"
>           ,"News - 4"
>         };
>
> foreach(var s in newsList)
> {
>
> string temp = s; //capture outside, use inside the lambda/delegate
>
> section.Add(new StringElement(s, () => {
>  DetailViewController dvc = new DetailViewController(temp);
>   this.NavigationController.PushViewController(dvc,true);
> });
>
>
> }
>
>
>
>
> On 5 March 2013 20:37, Iki <[hidden email]> wrote:
>> Hey Juan,
>>
>> Thanks for such quick response, as a matter of fact, my approach was exactly
>> like Your second solution.
>> But along the way I have made a mistake while assigning a new
>> DialogViewController, here is the example of working solution:
>>
>> public partial class MainViewController : DialogViewController
>> {
>>    List<string> newsList;
>>    List<StringElement> stringElementsList;
>>
>>    public MainViewController () : base (UITableViewStyle.Grouped, null)
>>    {
>>
>>       Root = new RootElement ("Main View") {};
>>       Section section = new Section ("");
>>
>>
>>        newsList = new List<string>()
>>        {
>>            "News - 1"
>>           ,"News - 2"
>>           ,"News - 3"
>>           ,"News - 4"
>>         };
>>
>>         stringElementsList = new List<StringElement> (){};
>>
>>         for (int i = 0; i < newsList.Count; i++)
>>         {
>>            StringElement se = new StringElement(newsList[i]);
>>            section.Add(se);
>>
>>            se.Tapped += () =>
>>            {
>>               //DialogViewController with modified ctor (string name)
>>                 DetailViewController dvc = new
>> DetailViewController(newsList[se.IndexPath.Row]);
>>                 this.NavigationController.PushViewController(dvc,true);
>>             };
>>
>>             stringElementsList.Add(se);
>>          }
>>
>>          Root.Add (section);
>>
>>
>>     }
>> }
>>
>>
>>
>> On Mar 5, 2013, at 8:11 PM, Juan M Gómez <[hidden email]> wrote:
>>
>> Hi Iki,
>> There are a few ways to go on:
>> ->Just a specialized class of StringElement that exposes your properties or
>> a new event.
>> ->If you assign the data in the same struct, just use it (if it is a loop,
>> remember to set a new assign in the block of lambda)
>>
>> cheers
>>
>>
>> Juan M Gómez
>>
>>
>> 2013/3/5 Iki <[hidden email]>
>>>
>>> Hi guys/gals,
>>>
>>> I'm having trouble accessing MonoTouch Dialog elements.
>>>
>>> Example is:
>>>
>>> I have a list of items from which i create StringElements in section.
>>> After elements is tapped, i would like to go to a new view, on which i
>>> would, based on the element tapped filled out the data.
>>>
>>> StringElement.Tapped is without parameters,
>>>
>>> se.Tapped += () =>
>>>                {
>>>
>>>
>>>                };
>>>
>>> and i can't find a proper way to send reference of the object that is
>>> tapped.
>>>
>>> I'm currently using DialogViewControllers, for my main view, on which i
>>> create list of name, and on my detail view which i need to fill up with data
>>> based on element from the main view.
>>>
>>> I did try with this
>>>
>>> public void RowSelected (UITableView tableView, NSIndexPath indexPath)
>>> {
>>>    DetailViewController dvc = new DetailViewController (names
>>> [indexPath.Row]);
>>>    this.NavigationController.PushViewController (dvc, true);
>>> }
>>>
>>> But I don't see any effect.
>>>
>>> Thanks!
>>>
>>>
>>>
>>> _______________________________________________
>>> MonoTouch mailing list
>>> [hidden email]
>>> http://lists.ximian.com/mailman/listinfo/monotouch
>>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>>
>>
>> _______________________________________________
>> MonoTouch mailing list
>> [hidden email]
>> http://lists.ximian.com/mailman/listinfo/monotouch
>>
>
>
>
> --
> Nic Wise
> t.  +44 7788 592 806 | @fastchicken
> b. http://www.fastchicken.co.nz/

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch