![](/img/trans.png)
[英]Unable to load WebView from TableView in PopOverController - Objective C
[英]Unable to Populate TableView In PopOverController - Objective C
我有一个名为UploadButton
的UIButton
。 我正在使用以下代码行来处理单击它时应该发生的动作:
-(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;
}
基本上,我想要的是单击我的UIPopOverController
,在UItableView
内显示一个UploadButton
。
但是,在运行上述代码行时,我在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
。 我在代码中尝试了很多变体,但是无法对其进行整理。 有人可以帮我吗 ?? 谢谢并恭祝安康。
问题是以下行:
self.keys1 = [NSMutableArray array];
您的UploadSpaceTableViewController
没有方法setKeys /属性键。
编辑第二条错误消息:
UITableView数据源必须从tableView:cellForRowAtIndexPath返回一个单元格:
这意味着您应该实现UITableViewDataSource
方法tableView:cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//configure your cell here
return myCongiuredTableViewCell;
}
该错误意味着在为keys1, self.keys1 = ...
赋值时,传递了无效的参数。 例如,如果将NSMutableArray传递给NSDictionary属性,则会收到该错误。
您是否分配了单元格,我认为通过您的代码它将返回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;
}
可以帮助您...
在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;
}
我认为这可能对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.