Matrix in XCode


(Andreas Kiel) #1

How to create one?
Can’t find them in IB.


(Shane Stanley) #2

They’re officially deprecated. If you have several radio-style buttons in the same parent view, connected to the same action, they will behave as a matrix. The only thing missing is an overall identity to bind to, so generally it’s easier to use a action handler.


(Andreas Kiel) #3

What do you mean by action handler?
A popup?

I want to get something like below

rows%20and%20matrix

Each row is a matrix with radio buttons.

I checked the amount of those “rows” the old app has: at least 25
So it’s quite a pain to handle.

My current code:

on checkButton:sender
	set nameId to sender's identifier
	set nameId to nameId as string
	set checkListKey to (nameId & "ValList") as string
	
	set radioList to (defaults's objectForKey:checkListKey)
	set radioCount to (count of radioList) as integer
	
	set someState to (sender's state)
	set someState to someState as integer
	
	set someTag to (sender's tag)
	set someTag to someTag as integer
	
	set foundVal to (item someTag of radioList) as integer
	if not foundVal = 1 then
		set tmpRadioList to (items 1 thru radioCount of {0, 0, 0, 0, 0, 0, 0, 0, 0}) as list
		set (item someTag of tmpRadioList) to someState
		repeat with zID from 1 to radioCount
			set theKey to (nameId & zID) as string
			set theObj to (item zID of tmpRadioList)
			(defaults's setObject:theObj forKey:theKey) -- set individual values
		end repeat
		defaults's setObject:tmpRadioList forKey:checkListKey -- replace list
        
	else -- button was already "checked"
		set theKey to (nameId & someTag) as string
		defaults's setObject:1 forKey:theKey
	end if -- not foundVal = 1 then
end checkButton:

works fine so far.
Maybe there is an idea to simplify it.

One thing which would simplify the work in IB:
I put the check boxes into a custom view, set Identifier, Tag and Binding Value once for a kind of prototype.
For each copy I need to set Identifier and Binding Value again.
It would be nice if some code would allow to recover the Identifier of the custom view - that would save a lot of work and helps to prevent errors.


(Shane Stanley) #4

A handler like that you’ve written.