إزالة بعض عرض من وحدة تحكم الرأي
-
03-07-2019 - |
سؤال
وأريد أن إزالة subview الحالي (المضافة atIndex: 0). من وجهة نظري تحكم عرض الجذر وتضاف طريقة عرض جديدة في مكانها
وحاليا يمكن أن أجد سوى مقتطفات الشفرة التي تظهر تفريغ العرض باستخدام removeFromSuperView، الأمر الذي يتطلب منك أن تعرف ما viewcontrollers يتم تحميل عرض حاليا.
والشيء الآخر الوحيد هو أن نلاحظ أن لدي subview آخر إدراجها في rootcontrollers عرض الذي أنا لا أريد تفريغ. لذلك الرمز الذي يزيل أي وجميع subviews ليست كافية
شكرا،
م
if(self.firstscr == nil)
{
firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
self.firstscr = f;
[f release];
}
///This is my attempt at getting to the currently loaded view :P
[[self.view subviews atIndex:0].view removeFromSuperView];
[self.view insertSubview:firstscr.view atIndex:0];
المحلول
وهنا هو كيف نفعل ذلك (أنا أحسب بها، YEY لي!)
if(self.firstscr == nil)
{
firstscreen *f = [[firstscreen alloc] initWithNibName:@"firstscreenview" bundle:nil];
self.firstscr = f;
[f release];
}
//Remove whatever view is currently loaded at index 0, this index is only to be used by "page" views
UIView *v = [self.view.subviews objectAtIndex:0];
[v removeFromSuperview];
[self.view insertSubview:firstscr.view atIndex:0];
لا تنتمي إلى StackOverflow