كيفية إضافة عرض جدول إلى وحدة التحكم في التنقل والتي تتم إضافتها في حد ذاتها كوحدة تحكم تابعة لطريقة عرض الطفل إلى UIViewController

StackOverflow https://stackoverflow.com//questions/21052870

سؤال

لقد تمت إضافة UIViewController باعتباره ChildViewController إلى UIViewController.

exampleView = [[UIViewController alloc] init];

//Setting the frame of the child UIViewController

CGRect frame = self.view.frame;
frame.origin.y = frame.origin.y + 83.0;
frame.size.height = 200.0;
exampleView.view.frame = frame;

[self addChildViewController:exampleView];
[self.view addSubview:exampleView.view];
[exampleView didMoveToParentViewController:self];

ثم أقوم بإضافة UINavigationController إلى ChildViewController

//Adding navigation controller to the child view.

UINavigationController *nav = [[UINavigationController alloc]     initWithRootViewController:exampleView];
nav.navigationBar.translucent = NO;
[exampleView.view addSubview:nav.view];
exampleView.title = @"mynameasdasd";

ملحوظة:أفعل ذلك لأنني أحتاج إلى أن تكون وحدة التحكم في التنقل في منتصف وجهة نظري (لا تشغل حجم الشاشة بالكامل).

أريد الآن إضافة TableView إلى وحدة التحكم في التنقل هذه ومتابعة التنقل العادي.كيف أفعل ذلك.لا أستطيع إضافة طريقة عرض جدول إلى وحدة التحكم في التنقل هذه.

هل كانت مفيدة؟

المحلول

المعلمة التي تنتقل إليها initWithRootViewController خطأ.وينبغي أن يكون هذا هو رأي UITableViewController

UITableViewController *tvc = [[UITableViewController alloc] init];
tvc.delegate = <Put your UITableViewDelegate here>
tvc.datasource = <Put your UITableViewDatasource here>
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:tvc];
nav.navigationBar.translucent = NO;
[exampleView.view addSubview:nav.view];
exampleView.title = @"mynameasdasd";

نصائح أخرى

You cannot add a table view to a navigation controller. You can only add a view controller containing a table view to a navigation controller.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top