I'm no pro at this, but I would do is something more like this:
lua Code:
local function CreateCheckboxes(subframe)
local boxes = AftermathUIFrame.checkboxes or {}
if subframe == 1 then
boxes[1] = Checkbox(AftermathhUIFrame, 1, 14, -95, "Show PvP Icon.", AftermathhUI.ouf.showpvpicon)
boxes[2] = Checkbox(AftermathhUIFrame, 2, 14, -115, "Show Buffs.", AftermathhUI.ouf.showbuffs, ShowBuffs_OnClick)
boxes[3] = Checkbox(AftermathhUIFrame, 3, 14, -135, "Show Debuffs.", AftermathhUI.ouf.showdebuffs)
-- and so on
elseif subframe == 2 then
boxes[1] = Checkbox(whatever)
elseif
else
end
for i = i, #boxes do
boxes[i]:Show()
end
AftermathUIFrame.checkboxes = checkboxes
end
local function ReleaseCheckboxes()
local boxes = AftermathUIFrame.checkboxes
local bin = AftermathUIFrame.recyclebin or {}
for i = 1, #boxes do
boxes[i]:Hide()
table.insert(bin, boxes[i])
boxes[i] = nil
end
end
local function DisplayCheckboxes(subframe)
ReleaseCheckboxes()
CreateCheckboxes(subframe)
end
AftermathhUIFrameSub1:SetScript("OnClick", DisplayCheckboxes(1))
That lets you keep track of the buttons you've created, recycle them when the user switches tabs so you don't just keep making new buttons, and you can reuse the same code for your other subframes, just adding their button configuration options to the creation function.
You would have to set up your Checkbox function to try to pull old buttons out of the recycle bin before creating new ones and to return the CheckButton object.