Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
委托和数据源在iOS中不适用于UIPopoverListView?_Ios_Objective C_Delegates_Datasource - Fatal编程技术网

委托和数据源在iOS中不适用于UIPopoverListView?

委托和数据源在iOS中不适用于UIPopoverListView?,ios,objective-c,delegates,datasource,Ios,Objective C,Delegates,Datasource,我已经从github下载了UIPopOverListView,并粘贴到我的工作区中,然后当单击按钮时,popoverlistview出现,但委托和数据源方法被调用,但无法正常工作, 当我的按钮被点击时 -(void) effectsButtonClicked { effectsPopView = [[UIPopoverListView alloc] initWithFrame:CGRectMake(10,150,300,200 )]; effectsPopView.delegate=self;

我已经从github下载了UIPopOverListView,并粘贴到我的工作区中,然后当单击按钮时,popoverlistview出现,但委托和数据源方法被调用,但无法正常工作,
当我的按钮被点击时

-(void) effectsButtonClicked
{
effectsPopView = [[UIPopoverListView alloc] initWithFrame:CGRectMake(10,150,300,200 )];
effectsPopView.delegate=self;
effectsPopView.datasource=self;
effectsPopView.listView.scrollEnabled = FALSE;
[effectsPopView setTitle:@"Effects"];
[effectsPopView show];
}
然后,我的数据源和代理

#pragma mark - UIPopOverListView DataSource

- (NSInteger)popoverListView:(UIPopoverListView *)popoverListView
   numberOfRowsInSection:(NSInteger)section
{
return 5;
}
- (UITableViewCell *)popoverListView:(UIPopoverListView *)popoverListView
                cellForIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"cell";
UITableViewCell * effectsCell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                         reuseIdentifier:identifier];

effectsArray=[NSArray arrayWithObjects:@"Black and White",@"Sepia",@"Hue",@"Snow",@"Normal", nil];
effectsCell.textLabel.text=[effectsArray objectAtIndex:indexPath.row];
effectsCell.textLabel.textColor=[UIColor redColor];
NSLog(@"%@",effectsArray);
return effectsCell;
}

#pragma mark- UIPopoverList Delegates

- (void)popoverListView:(UIPopoverListView *)popoverListView
 didSelectIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"ROw selected");
}  
屏幕截图是


有人能解释一下,为什么数据源和代理不工作吗?连接数据源有两种方法 从…起 (1) 从文件所有者添加
(2) 从界面上看,似乎内部
UIPopoverListView
实现了
UITableView
。在所有表视图数据源方法中,它都在调用您正在实现的公开的
datasource
方法

我认为,问题是
delegate
datasource
的赋值发生在调用
UITableView
数据源方法之后。设置
UIPopoverListView
datasource后,没有机制调用它们。作为一种解决方法,您可以实现一个
reload
方法,该方法只需在内部表视图实例上调用
reloadData

-(void) reload {
    if(_listView) {
        [_listView reloadData];
    }
}
在.h文件中声明此方法并在代码中调用它

 -(void) effectsButtonClicked
 {
      effectsPopView = [[UIPopoverListView alloc] initWithFrame:CGRectMake(10,150,300,200 )];
      effectsPopView.delegate=self;
      effectsPopView.datasource=self;
      effectsPopView.listView.scrollEnabled = FALSE;
      [effectsPopView setTitle:@"Effects"];
      //Call here before presenting.
      [effectsPopView reload];
      [effectsPopView show];
}

这可能不是理想的解决方案,只是一种变通方法。您应该在项目的github页面上提交一个bug,以便原始作者可以提供修复


希望有帮助

您必须在UIPOpoverListView类中实现类似default init的方法 或 您需要在PopOverletsView显示方法中重新加载表 -(无效)显示 { //在这里重新加载表格

}