为什么我的委托方法没有被调用?

时间:2014-09-12 09:38:44

标签: ios objective-c delegates

我正在使用CFViewController,我需要调用委托方法。

CFCoverFlowView.h

@class CFCoverFlowView;
@protocol CFCoverFlowViewDelegate <NSObject>

@optional
- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didScrollPageItemToIndex:(NSInteger)index;
- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index;

@end

@interface CFCoverFlowView : UIControl

@property (nonatomic, weak) id <CFCoverFlowViewDelegate> delegate;

CFViewController.h

@class CFCoverFlowView;

@interface CFViewController : UIViewController <CFCoverFlowViewDelegate>{
    int contador;
    CFCoverFlowView *coverFlowView2;
}

CFViewContorller.m

- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didScrollPageItemToIndex:(NSInteger)index {
    NSLog(@"didScrollPageItemToIndex >>> %@", @(index));

    self.pageControl.currentPage = index;

    contador++;
    if(contador == [computers count]){
        contador = 0;

    }
    pageControl2.currentPage = contador;
    NSLog(@"Scroll: %d", contador);

}

- (void)coverFlowView:(CFCoverFlowView *)coverFlowView didSelectPageItemAtIndex:(NSInteger)index {
    NSLog(@"didSelectPageItemAtIndex >>> %@", @(index));
}

我需要在滚动页面时调用最后两个函数。就像你有一个UITableView并且它调用了这个函数-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath有人可以帮助我吗? 谢谢你提前。

1 个答案:

答案 0 :(得分:1)

添加以下行:

[coverFlowView2 setDelegate:self];

您已在coverFlowView2中初始化CFViewController