13

मैं cellForRowAtIndexPathUITableView सेल में स्वाइप जेश्चर कैसे जोड़ें?

UISwipeGestureRecognizer *gestureR = [[UISwipeGestureRecognizer alloc] 
              initWithTarget:self action:@selector(handleSwipeFrom:)]; 
     [gestureR setDirection:UISwipeGestureRecognizerDirectionRight];//|UISwipeGestureRecognizerDirectionRight)]; 
     [cell addGestureRecognizer:gestureR]; 

में इस कोड को कहा कि यह ठीक काम करता है। लेकिन मैं चाहता हूँ UISwipeGestureRecognizerDirectionLeft तो यह

[gestureR setDirection:UISwipeGestureRecognizerDirectionLeft|UISwipeGestureRecognizerDirectionRight)]; 

की तरह जोड़ा जब मैं दिशा और राज्य के साथ मैं हमेशा 3 = 3

- (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer {  

    NSLog(@"%d = %d",recognizer.direction,recognizer.state); 
} 

हो रही है, तो मैं केवल एक इशारा यह ठीक काम करता है लागू की जाँच करें। मैंने दो इशारा एक-एक करके जोड़ने की कोशिश की। लेकिन यह केवल एक इशारा के लिए जवाब देगा।

दूसरा संकेत कैसे जोड़ें। मैंने टेबलव्यू को सीधे एक इशारा में जोड़ा और सेल में एक और अब उपयोग किया। आप बाएँ और दाएँ स्वाइप पर विभिन्न कार्यक्षमताओं को संभालने के लिए चाहते हैं

उत्तर

23

इस

 
UISwipeGestureRecognizer* gestureR; 
gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease]; 
gestureR.direction = UISwipeGestureRecognizerDirectionLeft; 
[view addGestureRecognizer:gestureR]; 

gestureR = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)] autorelease]; 
gestureR.direction = UISwipeGestureRecognizerDirectionRight; // default 
[view addGestureRecognizer:gestureR]; 

प्रयास करें, सिर्फ चयनकर्ताओं बदल जाते हैं।

+0

धन्यवाद, पहले से ही इस तरह की कोशिश की गई है लेकिन अलग-अलग फ़ंक्शन (चयनकर्ता) के साथ नहीं .. मैं कोशिश करता हूं और आपको बताता हूं ... +1 –

5

मुझे पता है कि यह उम्र बढ़ने के बाद से आप जानते हैं। लेकिन अपने प्रश्न में फिर से निम्नलिखित पंक्ति को आजमाएं और पढ़ें। [gestureR setDirection:UISwipeGestureRecognizerDirectionRight|UISwipeGestureRecognizerDirectionRight)];

क्या आपको एहसास हुआ कि आपने UISwipeGestureRecognizerDirectionRight जोड़ा है। दो बार !!

: डी

+0

हां .. ग्रेट कैच .. मेरा यह सिर्फ समस्या टाइप कर रहा है .. मैंने क्यू को फिर से अपडेट किया .. –

+0

धन्यवाद। सिर्फ रिकॉर्ड के लिए '[जेस्चरआर सेट डायरेक्शन: यूआईएसवाइप जेस्चर रिकॉग्नाइज़र डायरेक्शन लेफ्ट | यूआईएसवाइप जेस्चरर रिकॉग्नाइज़र डायरेक्शन राइट)];' बढ़िया काम करता है। Xcode 4.6.2 पर कोशिश की और परीक्षण किया – holierthanthou84

7

के बजाय दो बार alloc, यह बेहतर है अगर आप

UISwipeGestureRecognizer* recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)]; 
[recognizer setDirection:UISwipeGestureRecognizerDirectionLeft+UISwipeGestureRecognizerDirectionRight]; 
[cell addGestureRecognizer:recognizer]; 

का उपयोग हो सकता है और के रूप में कार्रवाई में कड़ी चोट की दिशा मिलेगा:

-(void)handleSwipe:(UISwipeGestureRecognizer *) sender 
{ 
    if (sender.direction == UISwipeGestureRecognizerDirectionLeft) 
    { 
    //do something 
    } 
    else //if (sender.direction == UISwipeGestureRecognizerDirectionRight) 
    { 
    //do something 
    } 
} 
संबंधित मुद्दे