我正在创建一个应用程序,其中我有一个UITableviewController
类,并且我有一个 IB 文件,其中包含一个UITableView
。在我的UIViewController
课程中,我正在创建一个UIPopOverController
导航控制器并将其分配给该弹出框的内容视图。在导航控制器中,rootView 是UITableView
控制器对象。我正在处理的问题是在单击其中显示 a 的 Bar Button 时显示 PopOver UITableView
。问题是它只显示空白表视图,因为表视图的委托和数据源方法永远不会被调用。这是我在调试时检查过的。我在这里粘贴我的代码。请回答为什么我的委托和数据源方法没有被调用。
这是 ViewController.m:-
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
arr_settings = [[NSMutableArray alloc]
initWithObjects:@"shikhar",@"gulshan",@"bhargav", nil];
//tbl_settings.delegate = self;
// tbl_settings.dataSource = self;
//self.title = @"Settings";
//arr_settings = [[NSMutableArray alloc]
initWithObjects:@"shikhar",@"gulshan",@"bhargav", nil];
// Custom initialization
}
return self;
}
-(IBAction)btn_settings:(id)sender{
TableViewController * settingstable = [[TableViewController alloc]
initWithNibName:@"TableViewController" bundle:Nil];
settingstable.tbl_settings.delegate = self;
settingstable.tbl_settings.dataSource = self;
//settingstable.tbl_settings.transform = CGAffineTransformMakeScale(1, 1);
//settingstable.tbl_settings.tag = 1;
//[self.view addSubview:settingstable.view];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:settingstable];
UIPopoverController * pickerPopover = [[UIPopoverController alloc]
initWithContentViewController:nav];
pickerPopover.delegate = self;
self.popovercontroller = pickerPopover;
//CGRect popoverRect = [self.view convertRect:[_btn_settings frame] fromView:
[_btn_settings superview]];
//popoverRect.size.width = MIN(popoverRect.size.width, 100);
pickerPopover.popoverContentSize = settingstable.tbl_settings.frame.size;
[settingstable.tbl_settings reloadData];
[pickerPopover presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section
{
NSLog(@"%u",[arr_settings count]);
return [arr_settings count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
if ([[UIDevice currentDevice] userInterfaceIdiom] ==
UIUserInterfaceIdiomPhone) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
cell.textLabel.text = [arr_settings objectAtIndex:indexPath.row];
NSLog(@"%@",cell.textLabel.text);
return cell;
}
我还在 TableViewController 类中声明了 TableView 的 IBOutlet。在 ViewController.h 类中已经提到了 Datasource 和 delegate 协议。如果提问的方式不对,请帮助我并原谅我。