无法在PopOverController中填充TableView - 目标C. [英] Unable to Populate TableView In PopOverController - Objective C

查看:90
本文介绍了无法在PopOverController中填充TableView - 目标C.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UIButton ,名为 UploadButton 。我正在使用以下代码行来处理点击它时应该发生的操作::

I have a UIButton called as UploadButton. I am using the following lines of code which takes care of the action which should happen on clicking it ::

-(IBAction)UploadButtonPressed:(id)sender{  

self.Upload = [[UploadSpaceTableViewController alloc] 
                         initWithStyle:UITableViewStylePlain];
self.UploadTableViewPopover = [[UIPopoverController alloc] 
                                initWithContentViewController:Upload];               

[self.UploadTableViewPopover presentPopoverFromBarButtonItem:sender 
                                permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

此处, UploadSpaceTableViewController 我是一个单独的课程。它具有以下功能::

Here, UploadSpaceTableViewController is a separate class which I have made. It has the following functions in it ::

- (void)viewDidLoad
{
[super viewDidLoad];


self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(150.0, 140.0);
self.keys1 = [NSMutableArray array];
[keys1 addObject:@"Red"];
[keys1 addObject:@"Green"];
[keys1 addObject:@"Blue"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [keys1 count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

// Configure the cell...

NSString *key1 = [keys1 objectAtIndex:indexPath.row];
cell.textLabel.text = key1;

return cell;
}

基本上,我想要的只是显示 UItableView点击我的 UploadButton ,在 UIPopOverController

Basically, all I want is to display a UItableView inside a UIPopOverController on the click of my UploadButton.

然而,在运行上面的代码行时,我在gdb中得到以下错误::

However, on running the above lines of code I am getting the following erre in gdb ::

splitView[4486:f803] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-06-27 14:05:05.531 splitView[4486:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:

这是我第一次尝试在 UIPopoverController中显示 UITableView 。我在代码中尝试了很多变化但是,我无法解决它。有人可以帮我吗 ??谢谢和问候。

This is the first time that I am trying to display a UITableView inside a UIPopoverController. I have tried a lot of variations in the code but, I am unable to sort it out. Can someone help me out ?? Thanks and regards.

推荐答案

您是否按照您的代码分配了您的单元格,它将返回nill

Have you allocated your cell i think by your code it will return nill

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
 static NSString *CellIdentifier = @"Cell";
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

 if(cell == nill){
      cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];  
}     
 // Configure the cell...

 NSString *key1 = [keys1 objectAtIndex:indexPath.row];
 cell.textLabel.text = key1;

 return cell;
}

这可以帮助你...

这篇关于无法在PopOverController中填充TableView - 目标C.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆