[MacRuby-devel] Failure with outlineView data source

Laurent Sansonetti laurent.sansonetti at gmail.com
Sat Apr 30 17:24:41 PDT 2011


Hi Malcolm,

Have you tried removing the #to_s call in the
outlineView:objectValueForTableColumn:byItem: method? An important
thing to keep in mind when writing an outline view data source is to
always return the same object reference for an item, not copies. The
references must also be unique.

Laurent

On Sat, Apr 30, 2011 at 4:07 PM, Malcolm F <malcfff at gmail.com> wrote:
> I'm getting crashes using an outlineView data source fed by an array of numbers. The crash happens after fiddling around in the view, usually after some variable small delay. Upon crash, the debugger is always stopped in 'class_getSuperclass'.
>
> The crash only happens using Integers or Floats over 12.
>
> I've simplified it down to this sparse MyDocument class that can be put into a document-based app. Put an outline view into MyDocument.xib and connect the datasource delegate to MyDocument.
>
> I'm new at this, so if an experienced MacRubyist can show me what I'm doing wrong, I will be very grateful.
> thanks, m
>
> <<code snippet start>>
> class MyDocument < NSDocument
>  attr_accessor :dataSourceArray
>
>  def init
>    super
>    if (self != nil)
>      # Add your subclass-specific initialization here.
>      # If an error occurs here, return nil.
>    end
>    self
>  end
>
>  def awakeFromNib
>    #@dataSourceArray = [1,2,3,4,5,6,7,8,9,10,11,12] #survives
>    @dataSourceArray = [1,2,3,4,5,6,7,8,9,10,11,12,13] #crashes, anything over 12
>
>    #@dataSourceArray = [0.to_i,8.to_i,116.to_i,224.to_i,400.to_i,1000.to_i] #crashes
>    #@dataSourceArray = 13.0 #float also crashes
>    #@dataSourceArray = [10]  #survives
>    #@dataSourceArray = [99] #crashes
>    #@dataSourceArray = 99 #crashes
>    #@dataSourceArray = 9 #survives
>    #@dataSourceArray = [NSNumber.numberWithInt(99)] #crashes
>    #@dataSourceArray = Array.new [117] #crashes
>    #@dataSourceArray = [1,2,3,4,[5,6],7,8,9,0] #survives
>    #@dataSourceArray = [0,8,116,224,400,1000] #crashes
>    #@dataSourceArray = [0.to_s,8.to_s,116.to_s,224.to_s,400.to_s,1000.to_s] #survives
>    #@dataSourceArray = [:zero,:eight,:onesixteen,:twotwentyfour,:fourhundred,:hundredyoh] #survives
>  end
>
>  def windowNibName
>   "MyDocument"
>  end
>
>  ################## DataSource for OV #######################
>  def outlineView(outlineView, numberOfChildrenOfItem:item)
>    if item.is_a? Array
>      return item.count
>    end
>    1
>  end
>  def outlineView(outlineView, isItemExpandable:item)
>    (item == nil) || ((item.is_a? Array) && (item.count > 0))
>  end
>  def outlineView(outlineView, child:index, ofItem:item)
>    #returns child item objects
>    if item == nil
>      return @dataSourceArray #root item
>    end
>    if item.is_a? Array
>      return item[index]
>    end
>    return nil
>  end
>  def outlineView(outlineView, objectValueForTableColumn:tableColumn, byItem:item)
>    # returns the object represented by the column at this item
>    item.to_s
>  end
>
> end
>
> <<code snippet end>>
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>


More information about the MacRuby-devel mailing list