Issues with native.textField

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:

Louie,

Which build are you using? I had similar issues with text (and buttons) not displaying with build 2100.  When I added the object to the group, it would not show.  When I remove the group:insert, they would show to the screen.

BTW, I experienced this in the simulator.  Haven’t tested it on a device yet.

I have the same issue. I am using corona build 2013.2114. It is working fine in corona simulator and apple device below iOS7. I got purple screen (all purple beside the textfield) when init or destroy a storyboard screen with native textfield object in iOS 7.

is this a corona bug?

@boscotwcheung,

Did you include the textfield in the group for the scene?  Remember, native objects like the textfield must be removed before you can remove the display group. 

Please look in your device’s console log to see if you are getting any errors.  If you need help getting to your console log please read:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thanks

Rob

I called removeSelf() to remove the textfield when I leave the scene. It looks strange that it is not only happen in leaving the scene but also goto the that scene. It only shows the textfields but can’t see all other display objects sometimes. And I found that all missing display objects will show up when I clicked on the textfields sometimes. I did checked the console log but no error when this is happening.

Edited:

Attached is the screen I saw. I found the problem also happen when I remove the textfield sometimes. It only happens on iOS 7 (I tested it on Xcode simulator in iOS 7.0.3)

Apologies for the delayed response to this. As of my last post I started using storyboard. Took me a bit to apply it to my entire application, but when it was done, I stopped experiencing this specific error.

I still couldn’t fix my problem. I am using storyboard as well. I tried to make some sample apps to duplicate the problem but I still don’t know how to reproduce the problem in sample apps. I am sure it is not my bug as I couldn’t see any error message in the console and the apps is actually not crash but everything become “transparent” with a black or purple colour background (i didn’t add any background colour myself) except the textfield. I couldn’t see my button on screen, however, I could still click on it and it has correct response!!! It only happens on iOS 7. I don’t know what is the combination to reproduce the problem. I am not sure if it is storyboard, widget, my config or build.settings file…

I tried build 2123 today and the problem is still exist.

Can you produce a sample app that demonstrates this issue?

Thanks

Rob

I finally find out how to reproduce the problem. The attached project can produce the problem in iOS 7. I am using Corona build 2014.2123.

If you deploy on iOS 7 device, you will see black screen sometimes. If you deploy on XCode simulator, you will see purple screen sometimes. This happen when placing or removing textfield from screen. However, the apps is not crash, just everything become “transparent” except the textfield.

I found that when I comment out the orientation in build.settings, the problem will gone.

Hi @boscotwcheung,

Can you file this same test project in an actual bug report?

http://developer.coronalabs.com/content/bug-submission

Thanks,

Brent

Sure

Can you post the bug ID number that was emailed to you to this thread?

Thanks

Rob

Case 29546

I think I have the same issue.  I’m creating four native.newTextFields and everything works fine in the Corona simulator, however, in the Xcode simulator I get a pink/magenta screen that overlays my entire screen and displays the four text fields.  

The catch is that the native text fields are inside a function that is only called when an “Edit” button is pressed.  Even without pressing the button - just entering the scene - the fields want to display and a colored pink/magenta screen fills the screen background.  If I comment out the function the issue goes away (but then I have no input fields)!

I’d like to be kept up-to-date on how this is resolved!  Thank you.

*** Update:  The following solved the issue for me ***

Forget about the “Edit” button and separate function above.  The following solved the native.newTextFields issue for me and its behavior is now consistent.  I had the following in my build settings:

orientation = 

    {

        default = “portrait”,

        content = “portrait”,

        supported = {“portrait”,“portraitUpsideDown”,},

    },

Removing the [content =  “portrait”,] line fixed the issue.  No idea why, but apparently this setting conflicts somehow with the native text fields.  So, my new build settings looks like this:

orientation = 

    {

        default = “portrait”,

        supported = {“portrait”,“portraitUpsideDown”,},

    },

I hope this helps.  Cheers!  -Keith

Louie,

Which build are you using? I had similar issues with text (and buttons) not displaying with build 2100.  When I added the object to the group, it would not show.  When I remove the group:insert, they would show to the screen.

BTW, I experienced this in the simulator.  Haven’t tested it on a device yet.

I have the same issue. I am using corona build 2013.2114. It is working fine in corona simulator and apple device below iOS7. I got purple screen (all purple beside the textfield) when init or destroy a storyboard screen with native textfield object in iOS 7.

is this a corona bug?

@boscotwcheung,

Did you include the textfield in the group for the scene?  Remember, native objects like the textfield must be removed before you can remove the display group. 

Please look in your device’s console log to see if you are getting any errors.  If you need help getting to your console log please read:

http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Thanks

Rob

I called removeSelf() to remove the textfield when I leave the scene. It looks strange that it is not only happen in leaving the scene but also goto the that scene. It only shows the textfields but can’t see all other display objects sometimes. And I found that all missing display objects will show up when I clicked on the textfields sometimes. I did checked the console log but no error when this is happening.

Edited:

Attached is the screen I saw. I found the problem also happen when I remove the textfield sometimes. It only happens on iOS 7 (I tested it on Xcode simulator in iOS 7.0.3)