Skip to content

app crashs on thrid navigation to View "the specified child already has a parent" #9

@lukemcredmond

Description

@lukemcredmond

SDK 3.3.0
OSX
Titanium Studio, build: 3.4.1

view

<Alloy>
    <View id="Wrapper">
        <Require type="widget" src="com.mcongrove.navigationBar" id="NavigationBar" image="logo.png" />
        <View id="content">
            <View id="NonRows">
                <Label id="heading" />
                <Label id="text" />
            </View>
            <Widget id="ptr" src="nl.fokkezb.pullToRefresh" onRelease="refreshList">
                <TableView id="container">
                    <Widget id="is" src="nl.fokkezb.infiniteScroll" onEnd="nextbatch" />
                </TableView>
            </Widget>
        </View>
    </View>
</Alloy>

controler

$.init = function() {
    $.is.init($.container);
    $.ptr.refresh();
};

function refreshList(e) {
    var callback = function(result) {
        ProcessResults(result);//builds up array and set it with this call  $.container.setData(rows);
        if (e) {
            e.hide();
        }
    };
    rows = [];
    _params.StartIndex = 0;
    _params.Force = true;
    $.GetData(e, callback);//Calls rest api to get the data
}

$.init();

using com.mcongrove.tabs for navigation and on selection i call a handleNavigation function,

handleNavigation : function(_id) {
            APP.Tabs.setIndex(_id);
            APP.currentStack = _id;

            // Create new controller stack if it doesn't exist
            if ( typeof APP.controllerStacks[_id] === "undefined") {
                APP.controllerStacks[_id] = [];
            }

            // Set current controller stack
            var controllerStack = APP.controllerStacks[_id];

            // If we're opening for the first time, create new screen
            // Otherwise, add the last screen in the stack (screen we navigated away from earlier on)
            var screen;

            APP.hasDetail = false;
            APP.previousDetailScreen = null;

            if (controllerStack.length > 0) {
                // Retrieve the last screen

                    screen = controllerStack[controllerStack.length - 1];

                    controllerStack[0].fireEvent("APP:screenAdded");

            } else {
                // Create a new screen
                var type = APP.Nodes[_id].type.toLowerCase();
                screen = Alloy.createController(type, APP.Nodes[_id]).getView();

                // Add screen to the controller stack
                controllerStack.push(screen);

                    screen.fireEvent("APP:screenAdded");

            }

            // Add the screen to the window
            addScreen(screen);

            // Reset the modal stack
            APP.modalStack = [];
        }
    }

addScreen : function(_screen) {
        if (_screen) {

                APP.ContentWrapper.add(_screen);

                if (APP.previousScreen) {
                    APP.removeScreen(APP.previousScreen);
                }

                APP.previousScreen = _screen;

        }
    }

the above code works perfect the first time, after navigating away and returning the 2nd time no error but list does not appear,

navigate away again and return to the view and exception is threw, in the processProperties function in the SwipeRefresh.java

i changed the function to

@Override
    public void processProperties(KrollDict d) {
        if (d.containsKey(PROPERTY_VIEW)) {
            Object view = d.get(PROPERTY_VIEW);
            if (view != null && view instanceof TiViewProxy) {
                this.view = (TiViewProxy) view;
                // view is table
                // layout is the SwipeRefreshLayout

                this.layout.setNativeView(this.view.getOrCreateView()
                        .getNativeView());

                try {
                    //this.layout.addView(this.view.getOrCreateView().getOuterView());
                    ViewGroup p = (ViewGroup)this.view.getOrCreateView().getNativeView().getParent();
                    if(p != null){
                        p.removeView(this.view.getOrCreateView().getNativeView());
                    }
                    this.layout.addView(this.view.getOrCreateView().getOuterView());

                } catch (Exception ex) {
                    Log.e("TiAPI", ex.getMessage());

                    ViewGroup p = (ViewGroup)this.view.getOrCreateView().getNativeView().getParent();
                    p.removeView(this.view.getOrCreateView().getNativeView());

                    this.layout.addView(this.view.getOrCreateView().getOuterView());
                }
                // this.layout.setVisibility(View.VISIBLE);
                // this.view.getOrCreateView().getOuterView().setVisibility(View.VISIBLE);

                this.layout.setColorScheme(color1, color2, color3, color4);
            }
        }
        super.processProperties(d);
    }

exception no longer occurs but the list is not displaying

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions