Developing on Mac OS, building for iOS, v2013.2076
Background:
- Hi all, I just recently started testing my app on iOS.
- Currently I am using an iPad 2, with iOS 7.0.2.
- I am not using director, as I though my app would just be simple.
- I finished testing and am ready for release on Android but wanted to have a concurrent release on iOS.
Problem:
- I have dialogs that use native.textField - primarily this is for search values
- I build dialogs by overlaying a new display.newGroup() over everything (noting of course that I cannot add a native.textField to a display group.
- I remove these dialogs by (1) handling the information, (2) calling textField.removeSelf() (3) calling group.removeSelf()
- All these dialogs work fine on android and simulator
- While on iOS Device - opening/closing a dialog with a native.textField will sometimes (the first time it is tried, and about 1 in 5 times after that) cause the screen to be all black save for the textField (or just all black if I close the dialog with a textField).
Sample Code:
[lua]
–Rename Dialog
local widget = require “widget”
local const = require “constants”
this = {}
this.render = function( curName, owner )
local group = display.newGroup()
local renameBox
local function cancelRename( event )
--print (“cancel rename”)
local e = {name = “saveRename”, cancel=true}
group:dispatchEvent(e)
renameBox:removeSelf()
renameBox = nil
group:removeSelf()
group = nil
return true
end
local mask = display.newRect(display.contentWidth*0.5, display.contentHeight*0.5, display.contentWidth, display.contentHeight)
mask:setFillColor(0, 0, 0, 180/255)
local block = function( event )
return true
end
mask:addEventListener(“touch”, block)
mask:addEventListener(“tap”, block)
local box = display.newRect( display.contentWidth*0.5, display.contentHeight*0.125+const.corePadding, display.contentWidth - const.corePadding*4, display.contentHeight*0.23)
box:setFillColor( const.searchR1, const.searchG1, const.searchB1 )
--Reminder Text
local checkLength = function(event)
local textField = event.target
local text = event.target.text
if string.len(text) > const.maxTeamNameLength then
text = string.sub(text, 1, const.maxTeamNameLength)
textField.text = text
end
return true
end
local toDisplay = “Name Your “…owner…”:”
local dialogText = display.newText(toDisplay, 0, 0, nil, const.disFontSize)
dialogText.x = display.contentWidth*0.5
dialogText.y = dialogText.contentHeight*0.5 + const.corePadding*3
dialogText:setFillColor(const.dgreyR, const.dgreyG, const.dgreyB)
--TextField
renameHeight = display.contentHeight/15
renameBox = native.newTextField( display.contentWidth*0.5, dialogText.height + const.corePadding*4 + renameHeight*0.5,
display.contentWidth - (const.corePadding * 8),
renameHeight)
renameBox.size = const.natFontSize
renameBox.text = curName
renameBox.align = “center”
renameBox:addEventListener(“userInput”, checkLength)
--Cancel Button
local cancelBtn = display.newRect(display.contentWidth/12 + const.dialogButtonWidth*0.5,
const.corePadding * 7 + renameBox.height + dialogText.height + const.dialogButtonHeight*0.5,
const.dialogButtonWidth, const.dialogButtonHeight)
cancelBtn:setFillColor(const.searchR1, const.searchG1, const.searchB1)
cancelBtn:addEventListener(“tap”, cancelRename)
local cancelLabel = display.newText{
text = “CANCEL”,
x = cancelBtn.x,
y = cancelBtn.y,
font = nil,
fontSize = const.searchBtnFontSize}
cancelLabel:setFillColor(const.dgreyR, const.dgreyG, const.dgreyB)
local saveRenameEvent = function(event)
--print(“Save rename”)
if string.len(renameBox.text) > 0 then
local e = {
name = “saveRename”,
cancel = false,
newName = renameBox.text
}
group:dispatchEvent(e)
renameBox:removeSelf()
renameBox = nil
group:removeSelf()
group = nil
elseif string.len(renameBox.text) == 0 then
local alert = native.showAlert( “Warning”, “You have not entered anything.”, { “OK” }, onComplete )
end
return true
end
local saveBtn = display.newRect(display.contentWidth - display.contentWidth/12 - const.dialogButtonWidth*0.5,
const.corePadding * 7 + renameBox.height + dialogText.height + const.dialogButtonHeight*0.5,
const.dialogButtonWidth, const.dialogButtonHeight)
saveBtn:setFillColor(const.searchR1, const.searchG1, const.searchB1)
saveBtn:addEventListener(“tap”, saveRenameEvent)
local saveLabel = display.newText{
text = “SAVE”,
x = saveBtn.x,
y = saveBtn.y,
font = nil,
fontSize = const.searchBtnFontSize}
saveLabel:setFillColor(const.dgreyR, const.dgreyG, const.dgreyB)
group:insert(mask)
group:insert(box)
group:insert(dialogText)
group:insert(cancelBtn)
group:insert(cancelLabel)
group:insert(saveBtn)
group:insert(saveLabel)
group.close = cancelRename
return group
end
return this
[/lua]
Screenshot: