无法在PopOverController中填充TableView - 目标C.

时间:2012-06-27 08:25:44

标签: iphone objective-c ios xcode ipad

我有一个名为UIButton的{​​{1}}。我正在使用以下代码行来处理单击它时应该发生的操作::

UploadButton

在这里,-(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

基本上,我想要的是在点击- (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内显示UIPopOverController

然而,在运行上面的代码行时,我在gdb ::

中得到以下错误
UploadButton

这是我第一次尝试在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: 内显示UITableView。我在代码中尝试了很多变化但是,我无法解决它。有人可以帮我吗 ??谢谢和问候。

4 个答案:

答案 0 :(得分:0)

问题在于以下几行:

self.keys1 = [NSMutableArray array];

您的UploadSpaceTableViewController没有方法setKeys /没有属性键。

编辑第二条错误消息:

  

UITableView dataSource必须从中返回一个单元格   的tableView:的cellForRowAtIndexPath:

这意味着您应该实施UITableViewDataSource方法tableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //configure your cell here

    return myCongiuredTableViewCell;
}

答案 1 :(得分:0)

当您为keys1,self.keys1 = ...分配值时,该错误意味着您传递了无效参数。例如,如果您将NSMutableArray传递给NSDictionary属性,则会收到该错误。

答案 2 :(得分:0)

你是否按照你的代码分配了你的单元格,它将返回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;
}

这可能会对你有帮助......

答案 3 :(得分:0)

在cellForRowAtIndexPath中使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    // Configure the cell...

    if( cell == nil )
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

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

    return cell;

}

我认为这对你有帮助。