2014-02-05 44 views
1

我已经下载从GitHub的UIPopOverListView,在我的工作区粘贴,然后单击,出现popoverlistview,而是一个按钮时,代表和数据源的方法被调用,但不能正常工作,
当点击我的按钮委托和数据源不适用于iOS中的UIPopoverListView?

-(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]; 
} 

然后我datasouce和代表们

#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"); 
} 

屏幕截图

enter image description here

任何人都可以解释,为什么数据源和代表不工作

回答

1

有拖的方式来数据源 从 连接(1)从文件的所有者 从接口(2)添加

0

看来,内部UIPopoverListView执行UITableView。在所有的表格视图数据源方法中,它正在调用您正在实施的已公开方法datasource

问题,我认为delegatedatasource的分配发生在调用UITableView数据源方法之后。在设置了UIPopoverListView数据源后,没有任何机制可以调用它们。作为解决方法,您可以实施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页面上提交一个错误,以便原始作者可以提供修补程序。

希望有帮助!

0

您必须实现像缺省的init方法在UIPOpoverListView类 或 您需要重新加载在popoverltstView表显示方法 - (无效)显示 {这里 //重载表

}

相关问题