【已解决】ScrollView添加子元素问题

scrollview 添加子元素为什么每次都默认到最后边。。本来有8个我删掉3个。但是添加的时候还是添加到index=7的位置了
//删除的代码

UIScrollView* ranking_scrollview = static_cast<UIScrollView*>(m_pUILayer->getWidgetByName(“ranking_ScrollView”));

Layout* shop_layout = static_cast<Layout*>(ranking_scrollview->getChildren()->objectAtIndex(0));

int index = ranking_scrollview->getChildren()->count()-1;
ranking_scrollview->getChildren()->removeObjectAtIndex(index);

//添加的代码
唀IScrollView* ranking_scrollview = static_cast<UIScrollView*>(m_pUILayer->getWidgetByName(“ranking_ScrollView”));

UIPanel* panel=UIPanel::create();
panel->setTouchEnable(true);
panel->setSize(CCSizeMake(118,44));
panel->setBackGroundImage(“cocosgui/gui_examples/DemoShop/slot.png”);

UILabel* label1=UILabel::create();
label1->setText(“sdfsdfsdf”);
label1->setPosition(ccp(50,20));
panel->addChild(label1);

UILabel* label2=UILabel::create();
label2->setText(“sdfsdfsdf”);
label2->setColor(ccc3(255,0,0));
label2->setPosition(ccp(150,20));
panel->addChild(label2);

ranking_scrollview->addChild(panel);

本身就应该添加到最后吧?这个索引为7不应该啊8还有理由

索引从0开始。。仔细看了下。。解决了。。添加的时候自己写坐标
贴出代码供大家参考。。不知道还有没有简单的方法。有的话。可以跟帖。告诉我一声。。

        panel->addChild(label2);  

        int count = ranking_scrollview->getChildren()->count();
        UIWidget* d=(UIWidget*) ranking_scrollview->getChildren()->objectAtIndex(count-1);
        panel->setPosition(ccp(0,d->getPosition().y - d->getContentSize().height - 2));
        
        ranking_scrollview->addChild(panel);