[MacRuby-devel] HotCocoa table_view and the doubleAction

Dave Baldwin dave.baldwin at dsl.pipex.com
Wed Apr 1 05:39:52 PDT 2009


Quoting John Shea <johnmacshea at gmail.com>:

 > Hi Dave,
 >
 > I am actually wrestling with a similar problem.
 >
 >   I believe I have solved your problem, maybe you can solve  
mine ;-) ??
 >
 > in the start method I placed:
 >        @my_table_view.setTarget(self)
 >        @my_table_view.setDoubleAction(:double)
 >
 >
 > and then later on a method:
 >
 >    def double
 >      NSLog ("double")
 >    end
 >

This worked so thanks, but did have the side effect of making the  
single click action fail.  I think this was because I was setting it  
up using

	@tableView.on_action do
		NSLog "got table action via on_action..."
	end

which seems to add the action method to a proxy object and behind the  
scenes sets target to the proxy object.

Easily fixed by
	@tableView.target = self
	@tableView.doubleAction = 'double:'
	@tableView.action = 'single:'

and
	def double (sender)
	end

	def single (sender)
	end

In actual fact I was also using the tableViewSelectionDidChange   
delegate so was finding out about single clicks twice.

 >
 > My issue is also delegating table updates to certain methods.
 >
 > I noticed that tableview.setDelegate(self) did not do anything - and
 > then I assumed that the TableDataSource is actually handling the
 > delegate  - confirmed when I changed the numberOfRowsInTableView
 > method to return the value 1.

I haven't had any problems using delegate methods. For example I do:

	@tableView.delegate = self

and define a delegate method:

	def tableView (table, shouldEditTableColumn: c, row: r)
		false
	end

as you get told which tableView is 'calling' you you can use this to  
do table specific actions if one object is acting as a delegate for  
two tableViews.  More commonly the tableView is looked after by its  
own instance object so the setting of the delegate of the tableView  
will be unique for the different tableViews.

If you don't get the delegate's method signature correct they it will  
look like the delegate isn't working.

 >
 > But then I assume that I am not supposed to add my own tableView(tv,
 > setObjectValue:anObject, forTableColumn:col, row:row) method to the
 > HotCocoa TableDataSource file?

I don't believe so.

 >
 > What happens if I have two tables in the one application with
 > different delegated behaviour?

Use two objects - one per tableView - to customise the delegated  
behaviour you want, or use the table argument to the delegate method  
so choose the behaviour.

 >
 > Am I supposed to get funky and add the different versions of the
 > tableView methods to the data instance itself?
 > Is there a way to override the delegate dispatch to actually go a
 > local class?

I think this is what the setDelegate method does.

Hope this helps,

Dave.

 >
 > or do I setActions like in the double clicked example above?
 >
 > Cheers and thanks,
 > J
 >
 > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20090401/28fb17cb/attachment-0001.html>


More information about the MacRuby-devel mailing list