0

サブビューにオプションのプロトコルを実装したかったのです。サブビュー クラスは uiviewcontroller によって継承され、ほとんどのビュー コントローラーはこのサブビューによって継承されます。シンプルな構造だと思います。

問題は、シミュレーターでのみ機能することです。デバイスでは、最初の nslog だけが表示され、その後アプリケーションが閉じます。シミュレーターでは正常に動作します。

どうなり得るか ?

確かに、コメントアウトされているものもありますが、それらには何の努力もありません。

プロトコル:

@protocol CustomGestures <NSObject>

@optional

-(void)nextPage;   
-(void)previousPage;

@end

サブビューコントローラーの一部

@implementation SubViewController

//handles gestures and passes them
//further to the superclass
//uiviwcontroller to take the normal behaviour

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    //pass the information to superclass    
    [super touchesEnded:touches withEvent:event];   
    //create object with protocol and some other objects    
    id<CustomGestures> gestures;    
    UITouch* touch = [touches anyObject];   
    CGPoint currentPosition = [touch locationInView:self.view];

    CGFloat deltaX = gestureStartPoint.x - currentPosition.x;   
    CGFloat deltaY = fabs(gestureStartPoint.y - currentPosition.y);      
    //if the subclass (self) has the protocol implemented, use the protocoll-features   
    if ([self conformsToProtocol:@protocol(CustomGestures)])
    {       
        if (deltaX <= -80 && deltaY <= 20) { 
            NSLog(@"vorige seite");
            [gestures nextPage]; 
        } else 
            if (deltaX >= 80 && deltaY <= 20) {
                [gestures previousPage];
                 NSLog(@"nächste seite");
             }
         }

     }
}

サブビューの一部

 @interface NavInfos :
 SubViewController <CustomGestures>{
 ....}
 @implementation NavInfos
 //CustomGestures-Protocol

 -(void)nextPage{   
    NSLog(@"nächste seite im navinfos");     
    //[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://mapkit"]];//applyAnimated:YES]     
 }
 -(void)previousPage{   
     NSLog(@"vorige seite im navinfos");

    //[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://windows"]];
    //applyTransition:UIViewAnimationTransitionFlipFromLeft] applyAnimated:YES] 
 }
4

1 に答える 1

2

まず第一に、これらの 2 つのメソッドを@optionalチェックとして宣言しているため、問題のメソッドに応答することを確認するにconformsToProtocol:不十分です。キーワードを削除するか、取引 と同様に@optionalチェックを追加する必要があります。respondsToSelector:conformsToProtocol:

あなたの問題に関しては、ジェスチャーを何にも設定していませんが、とにかくメソッドを呼び出しています。それを何かに設定するか (例: self)、または 2 つの呼び出しを から[gestures ...]に切り替え[self ....]ます。

于 2010-08-02T17:05:12.497 に答える