Quantcast

Dequeuing table cells?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Dequeuing table cells?

Michael McGlothlin
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Jeff Stedfast
Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Michael McGlothlin
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Rolf Bjarne Kvinge
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Michael McGlothlin
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Rolf Bjarne Kvinge


On Wed, Jan 14, 2015 at 8:21 PM, Michael McGlothlin <[hidden email]> wrote:
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



This is not a correct pattern, iOS will not call the constructors that set the Subtitle constructors.

However I'm not sure what the correct code is; a quick google search indicates that you'll need a constructor that takes an NSCoder, but that might not be correct.

I recommend that you ask in the forums or on stackoverflow, that'll get much more visibility to your question (few people read this mailing list now).

Rolf

 

If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Michael McGlothlin
Apple's docs for UITableView dequeueReusableCellWithIdentifier:forIndexPath: clearly says that when a new cell must be created the initWithStyle:reuseIdentifier: constructor is called. This doesn't seem to happen with MonoTouch as it calls the IntPtr constructor. Mono's API docs for iOS don't say anything on the subject under either Classic or Unified. Articles and SO seem to agree that this is the behavior expected.


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 15, 2015, at 3:03 AM, Rolf Bjarne Kvinge <[hidden email]> wrote:



On Wed, Jan 14, 2015 at 8:21 PM, Michael McGlothlin <[hidden email]> wrote:
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



This is not a correct pattern, iOS will not call the constructors that set the Subtitle constructors.

However I'm not sure what the correct code is; a quick google search indicates that you'll need a constructor that takes an NSCoder, but that might not be correct.

I recommend that you ask in the forums or on stackoverflow, that'll get much more visibility to your question (few people read this mailing list now).

Rolf

 

If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Rolf Bjarne Kvinge
Hi,

You don't have the initWithStyle:reuseIdentifier: constructor, try adding this:

    [Export ("initWithStyle:reuseIdentifier:")]
    public UITableViewCell (UITableViewCellStyle style, NSString reuseIdentifier) : base (style, reuseIdentifier)
    {
    }

to your class and see if it's called.

Rolf       

On Fri, Jan 16, 2015 at 6:56 PM, Michael McGlothlin <[hidden email]> wrote:
Apple's docs for UITableView dequeueReusableCellWithIdentifier:forIndexPath: clearly says that when a new cell must be created the initWithStyle:reuseIdentifier: constructor is called. This doesn't seem to happen with MonoTouch as it calls the IntPtr constructor. Mono's API docs for iOS don't say anything on the subject under either Classic or Unified. Articles and SO seem to agree that this is the behavior expected.


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 15, 2015, at 3:03 AM, Rolf Bjarne Kvinge <[hidden email]> wrote:



On Wed, Jan 14, 2015 at 8:21 PM, Michael McGlothlin <[hidden email]> wrote:
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



This is not a correct pattern, iOS will not call the constructors that set the Subtitle constructors.

However I'm not sure what the correct code is; a quick google search indicates that you'll need a constructor that takes an NSCoder, but that might not be correct.

I recommend that you ask in the forums or on stackoverflow, that'll get much more visibility to your question (few people read this mailing list now).

Rolf

 

If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Michael McGlothlin
That attribute seems to be exactly what I needed. I hadn’t considered the need to export it and didn’t see it suggested anywhere. I seem to not need to include the constructor for the pointer if I have this constructor and it appears the default reuseIdentifier is the same thing I was manually assigning - the FullName of the cell type.

So I can drop all that and this simple class does the trick:


 public class SubtitleTableViewCell : UITableViewCell {
  [Export ( "initWithStyle:reuseIdentifier:" )]
  private SubtitleTableViewCell ( UITableViewCellStyle style, NSString reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {}
 }




On 2015 01 19, at 05:22, Rolf Bjarne Kvinge <[hidden email]> wrote:

Hi,

You don't have the initWithStyle:reuseIdentifier: constructor, try adding this:

    [Export ("initWithStyle:reuseIdentifier:")]
    public UITableViewCell (UITableViewCellStyle style, NSString reuseIdentifier) : base (style, reuseIdentifier)
    {
    }

to your class and see if it's called.

Rolf       

On Fri, Jan 16, 2015 at 6:56 PM, Michael McGlothlin <[hidden email]> wrote:
Apple's docs for UITableView dequeueReusableCellWithIdentifier:forIndexPath: clearly says that when a new cell must be created the initWithStyle:reuseIdentifier: constructor is called. This doesn't seem to happen with MonoTouch as it calls the IntPtr constructor. Mono's API docs for iOS don't say anything on the subject under either Classic or Unified. Articles and SO seem to agree that this is the behavior expected.


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 15, 2015, at 3:03 AM, Rolf Bjarne Kvinge <[hidden email]> wrote:



On Wed, Jan 14, 2015 at 8:21 PM, Michael McGlothlin <[hidden email]> wrote:
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



This is not a correct pattern, iOS will not call the constructors that set the Subtitle constructors.

However I'm not sure what the correct code is; a quick google search indicates that you'll need a constructor that takes an NSCoder, but that might not be correct.

I recommend that you ask in the forums or on stackoverflow, that'll get much more visibility to your question (few people read this mailing list now).

Rolf

 

If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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
|  
Report Content as Inappropriate

Re: Dequeuing table cells?

Sergei Kvasov
Guys, how did I get in this thread?

Best,
Sergei Kvasov



On Jan 20, 2015, at 12:39 AM, Michael McGlothlin <[hidden email]> wrote:

That attribute seems to be exactly what I needed. I hadn’t considered the need to export it and didn’t see it suggested anywhere. I seem to not need to include the constructor for the pointer if I have this constructor and it appears the default reuseIdentifier is the same thing I was manually assigning - the FullName of the cell type.

So I can drop all that and this simple class does the trick:


 public class SubtitleTableViewCell : UITableViewCell {
  [Export ( "initWithStyle:reuseIdentifier:" )]
  private SubtitleTableViewCell ( UITableViewCellStyle style, NSString reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {}
 }




On 2015 01 19, at 05:22, Rolf Bjarne Kvinge <[hidden email]> wrote:

Hi,

You don't have the initWithStyle:reuseIdentifier: constructor, try adding this:

    [Export ("initWithStyle:reuseIdentifier:")]
    public UITableViewCell (UITableViewCellStyle style, NSString reuseIdentifier) : base (style, reuseIdentifier)
    {
    }

to your class and see if it's called.

Rolf       

On Fri, Jan 16, 2015 at 6:56 PM, Michael McGlothlin <[hidden email]> wrote:
Apple's docs for UITableView dequeueReusableCellWithIdentifier:forIndexPath: clearly says that when a new cell must be created the initWithStyle:reuseIdentifier: constructor is called. This doesn't seem to happen with MonoTouch as it calls the IntPtr constructor. Mono's API docs for iOS don't say anything on the subject under either Classic or Unified. Articles and SO seem to agree that this is the behavior expected.


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 15, 2015, at 3:03 AM, Rolf Bjarne Kvinge <[hidden email]> wrote:



On Wed, Jan 14, 2015 at 8:21 PM, Michael McGlothlin <[hidden email]> wrote:
 public class SubtitleTableViewCell : UITableViewCell {
  public SubtitleTableViewCell () : this ( typeof ( SubtitleTableViewCell ).FullName ) {
  }


  public SubtitleTableViewCell ( string reuseIdentifier ) : base ( UITableViewCellStyle.Subtitle, reuseIdentifier ) {
  }


  protected SubtitleTableViewCell ( IntPtr handle ) : base ( handle ) {
  }
 }



This is not a correct pattern, iOS will not call the constructors that set the Subtitle constructors.

However I'm not sure what the correct code is; a quick google search indicates that you'll need a constructor that takes an NSCoder, but that might not be correct.

I recommend that you ask in the forums or on stackoverflow, that'll get much more visibility to your question (few people read this mailing list now).

Rolf

 

If I use a class like this then I get a cell of the default style. If I don't pass the pointer to base ( handle ) then it uses the subtitle style.


On Wed, Jan 14, 2015 at 12:55 PM, Rolf Bjarne Kvinge <[hidden email]> wrote:
Hi,

You should chain to the corresponding base constructor like this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

if that doesn't work, something else is going wrong. Can you show your MyTableViewCell code?

Rolf

On Wed, Jan 14, 2015 at 6:16 PM, Michael McGlothlin <[hidden email]> wrote:
In experimenting it seems you need an actual subclass to set the cell style as you never manually call the cell constructor and there is no other way to choose the style.

If I pass the handle to base ( handle ) it appears that the default constructor, that configures the style and reuse identifier by passing these to base ( style, reuseIdentifier ), never gets called?

I probably won't actually use the styles anyway but it doesn't seem to work as I'd expect. Mostly trying to get a clearer picture of what is going on. Since starting transitioning to Universal I've noticed several behaviors that seem odd. Trying to determine if I'm doing something new, if things changed, or if they're bugs.

I noticed yesterday that it is now ok for that special constructor to be protected instead of public. It didn't work on one computer but did on the other .. after the second finished updating Xamarin Studio then it worked on both. So I guess it's actively being worked on?


Thanks,
Michael McGlothlin
Sent from my iPhone

On Jan 14, 2015, at 10:49 AM, Jeff Stedfast <[hidden email]> wrote:

Hi Michael,

Hopefully one of the Xamarin.iOS devs can chime in, but the IntPtr handle that is passed to .ctors is the native object pointer.

If you don't pass it to base, then what happens is that the Xamarin.iOS runtime creates a new native instance.

My understanding is that you have this:

public MyTableViewCell (IntPtr handle) : base (handle)
{
...
}

and that you are removing the call to base()...

You shouldn't be doing that afaik.

This .ctor is meant only to be used by the runtime itself and should not be invoked by your code (it doesn't sound like you are invoking it yourself, but just in case that wasn't obvious).

I'm not sure if that really helps answer your overall question, but hopefully it at least helps clarify things a little bit for you.

Jeff

On Wed, Jan 14, 2015 at 11:40 AM, Michael McGlothlin <[hidden email]> wrote:
It appears that custom UITableViewCells must have a constructor that takes IntPtr for the automatic reuse to work but I can't see anywhere that says what this pointer is? It seems if I pass the pointer to the base that the cell doesn't work right but if I ignore the pointer it does work right?

Thanks,
Michael McGlothlin
Sent from my iPhone
_______________________________________________
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


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