【发布时间】:2015-11-20 12:20:20
【问题描述】:
我有一个启用了节页脚的UICollectionView。我创建了一个名为LeafletFooterView 的UICollectionReusableView 的自定义子类,并声明了一些IBOutlets 和IBActions:
- (IBAction)dropboxButton:(id)sender;
- (IBAction)soundcloudButton:(id)sender;
在我的UICollectionViewClass 中,我有:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionFooter) {
UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
reusableview = footerview;
}
return reusableview;
}
在LeafletFooterView 类的IBAction 中,我只是想呈现另一个viewController:
- (IBAction)dropboxButton:(id)sender
{
VideoWebViewController *video = [[VideoWebViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:video];
[self presentViewController:navigation animated:YES completion:nil];
[video setSelectedVideo:@"https://www.dropbox.com/"];
}
错误是:
No visible @interface for 'LeafletFooterView' declares the selector 'presentViewController:animated:completion'.
我已经在IBAction 方法中尝试了[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"www.dropbox.com"]];,虽然现在没有错误,但单击它不会打开带有网站的Safari。该方法肯定被调用; NSLog 和 Breakpoint 证明了这一点。
更新
因此,在那之后不起作用,我尝试为此声明 Delegates 的过程,与这个问题的方式大致相同:Present view controller from NSObject subclass。
这是我的LeafletFooterView:
@class LeafletFooterView;
@protocol FooterViewDelegate <NSObject>
-(void)rowTapped;
@end
@interface LeafletFooterView : UICollectionReusableView
@property (weak, nonatomic) IBOutlet UILabel *label;
- (IBAction)dropboxButton:(id)sender;
@property(nonatomic,assign)id<FooterViewDelegate> delegate;
The LeafletFooterView.m is here: - (IBAction)dropboxButton:(id)sender
{
NSLog(@"Dropbox");
[self.delegate rowTapped];
}
现在在我的LeafletCollectionViewController,我有:
- (void)rowTapped
{
NSLog(@"Is this getting called?");
VideoWebViewController *video = [[VideoWebViewController alloc] init];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:video];
[self presentViewController:navigation animated:YES completion:nil];
[video setSelectedVideo:@"https://www.dropbox.com/"];
}
当我运行这段代码时,这个方法实际上从未被调用过。 LeafletCollectionView 设置为使用FooterViewDelegate。在LeafletCollectionView 的viewWillAppear 中,我尝试了以下操作:
LeafletFooterView *footer = [[LeafletFooterView alloc] init];
footer.delegate = self;
仍然没有真正调用rowTapped 方法。
用户应该能够单击LeafletFooterView 中的UIButton 并显示UIViewController。我该如何实现这一目标?任何指导将不胜感激。
【问题讨论】:
标签: ios objective-c uiviewcontroller uicollectionview