UITableView dataSource必须在UIPopoverController

时间:2015-05-06 16:20:05

标签: ios iphone uitableview uipopovercontroller

我有一个显示表视图的UIPopoverController。

我按照以下方式遇到了崩溃:

  

,/ SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:6509   2015-05-06 17:12:05.795下一页[39510:607] *由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:' UITableView dataSource必须从tableView返回一个单元格:的cellForRowAtIndexPath:'   * 第一次抛出调用堆栈:   (       0 CoreFoundation 0x037691e4 __exceptionPreprocess + 180       1 libobjc.A.dylib 0x0341e8e5 objc_exception_throw + 44       2 CoreFoundation 0x03769048 + [NSException raise:format:arguments:] + 136       3基础0x014284de - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116       4 UIKit 0x025c0d7f __53- [UITableView _configureCellForDisplay:forIndexPath:] _ block_invoke + 426

如果我将sectionOfRows in section设置为0,我会看到tableView

如果我将行数设置为1,则会导致此崩溃,因此正在显示该表,并且需要显示单元格。

CellForRowAtIndexPath NEVER 被调用,因此崩溃。这是为什么?

在IB

中正确设置了Delegate和dataSource

根据以下内容启动并提出意见:

TablePickerViewController* picker = [[TablePickerViewController alloc] initWithSelectableOptions:options selectedIndex:selectedIndex selectionBlock:selectionBlock];

self.popover2 = nil;


self.popover2 = [[UIPopoverController alloc] initWithContentViewController:picker];

self.popover2.popoverContentSize = CGSizeMake(300, 200);

self.popover2.delegate = self;

picker.popover = self.popover2;

[self.popover2 presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

return picker;

为了澄清,传递到现在的框架是0,0,1024,768(横向方向)

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;

}

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


UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentt forIndexPath:indexPath];

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

cell.accessoryType = UITableViewCellAccessoryNone;
if (self.selectedIndex == indexPath.row) {
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
cell.textLabel.attributedText = self.options[indexPath.row];

return cell;

0 个答案:

没有答案