8

में शुरू हुआ मैं अपने UITableViewController उपवर्ग में इस विधि को परिभाषित कर रहा हूँ:छूता UITableViewController

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesBegan:touches withEvent:event]; 
    NSLog(@"touch began"); 
} 

लेकिन यह ट्रिगर नहीं किया जा रहा है। UIViewController UIResponder का उप-वर्ग है इसलिए इसे काम करना चाहिए, है ना? धन्यवाद

उत्तर

4

हाँ, यह निश्चित रूप से काम करना चाहिए।

सुनिश्चित करें कि उपयोगकर्ता नियंत्रक सक्षम इस नियंत्रक के दृष्टिकोण के लिए सेट है।

यदि दृश्य को निब/xib से लोड किया गया है, तो सुनिश्चित करें कि फ़ाइल का स्वामी उचित वर्ग नाम होने के लिए सेट है, और फ़ाइल के स्वामी का view आउटलेट उचित दृश्य से जुड़ा हुआ है।

अद्यतन: मैं इस व्यवहार के साथ-साथ देखते हैं, किसी ऐप एनएवी आधारित अनुप्रयोग टेम्पलेट के साथ बनाया का उपयोग कर, लेकिन उम्मीद के रूप में एक दृश्य के आधार पर अनुप्रयोग टेम्पलेट के साथ, यह काम करता है।

मुझे लगता है कि एक नेविगेशन नियंत्रक के मामले में, दृश्य नियंत्रक में एम्बेडेड तालिका दृश्य दृश्य नियंत्रक से पहले ईवेंट प्राप्त कर रहा है। UIView reference (जोर मेरा) देखें:

देखें नियंत्रकों खुद को UIResponder वर्ग की वंशज हैं और प्रबंधित रूट दृश्य और उसके superview, जो आम तौर एक अलग के अंतर्गत आता है के बीच प्रत्युत्तर श्रृंखला में डाला जाता है नियंत्रक देखें। यदि दृश्य नियंत्रक का दृश्य किसी ईवेंट को संभाल नहीं करता है, तो देखें नियंत्रक के पास विकल्प पर्यवेक्षण के साथ ईवेंट को पास करने से पहले ईवेंट को संभालने का विकल्प है।

इसका तात्पर्य है कि दृश्य में ईवेंट को संभालने का पहला मौका है, और यदि ऐसा होता है, तो दृश्य नियंत्रक इसे प्राप्त नहीं करेगा।

बिल्कुल सही नहीं है कि आप क्या करने की कोशिश कर रहे हैं, इसलिए मुझे यकीन नहीं है कि कौन सा समाधान पेश करना है।

+0

अरे, आपके उत्तर के लिए धन्यवाद। मैंने एक नया एक्सकोड नेविगेशन प्रोजेक्ट बनाया और UITableViewController उपclass में touchesbegan विधि को जोड़ा (कुछ और नहीं बदला), लेकिन यह – sumderungHAY

+0

काम नहीं करता है हां, मैं उस व्यवहार को भी देखता हूं - मेरा जवाब अपडेट किया गया। – zpasternack

+1

आपके विस्तृत उत्तर के लिए धन्यवाद। असल में, मेरे पास UIKeyboardTypeNumber पैड के UITextField है, और जब भी उपयोगकर्ता स्क्रीन पर कहीं भी क्लिक करता है तो मैं पहले उत्तरदाता (कीबोर्ड को खारिज कर देता हूं) इस्तीफा देना चाहता हूं। – sumderungHAY

3

मैं मूल पोस्टिंग के रूप में सटीक मुद्दे में भाग गया। मुझे UITableView का सबक्लास बनाकर और "touchesBegan" विधि को ओवरराइड करके इस मुद्दे के आसपास मिल गया। मैंने प्रोटोकॉल भी बनाया ताकि UITableView UITableViewController पर एक विधि को कॉल कर सके, जो आखिरकार मैं "स्पर्श्सबगन" ईवेंट को संभालना चाहता था।

@protocol AGSTableViewDelegate; 

@interface AGSTableView : UITableView 
@property (nonatomic, weak) id<AGSTableViewDelegate> agsDelegate; 
@end 

@protocol AGSTableViewDelegate<NSObject> 
-(void)tableViewTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event; 
@end 

और कार्यान्वयन:

यहाँ UITableView उप-प्रकार के लिए शीर्षक है

@implementation AGSTableView 

@synthesize agsDelegate; 

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{  
    [super touchesBegan:touches withEvent:event]; 

    if (agsDelegate) 
     [agsDelegate tableViewTouchesBegan:touches withEvent:event]; 
} 
@end 

और अंत में, UITableViewController से कोड के टुकड़े:

@interface AGSWasteUpdateTableController()<AGSTableViewDelegate> 
@end 

- (void)viewDidLoad 
{ 
    AGSTableView *tableView = (AGSTableView *)[self tableView]; 
    tableView.agsDelegate = self; 
} 

-(void)tableViewTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [yourTextField resignFirstResponder]; 
} 

आशा इस मदद करता है ..

5

यदि आप UITableViewController में कीबोर्ड को खारिज करने का प्रयास कर रहे हैं, तो एक सभ्य समाधान तालिका में इस्तीफा कॉल करने के लिए है। प्रतिनिधि प्रतिनिधि ने किया है चयन करें RowAtIndexPath विधि।

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [myTextField resignFirstResponder]; 

    // Rest of your actual didSelectRowAtIndexPath code ... 
} 
+0

अरे मुझे एक ही समस्या थी। स्वीकार्य उत्तर में उपरोक्त टिप्पणियों से, यह स्पष्ट है कि @sumderungHAY को अपनी समस्या हल नहीं हुई, लेकिन यह अभी भी स्वीकार कर लिया गया है! लेकिन आपका समाधान मेरे लिए काम करता है !!! –

1

आपको प्रतिक्रियाकर्ता श्रृंखला को छूने की आवश्यकता है। हम UITableView को उप-वर्गीकृत करके और ओवरराइडिंग स्पर्श कर सकते हैं बेगान (और यदि आवश्यक हो तो अन्य) और फिर उत्तरदाता श्रृंखला को UITableViewController पर छूएं।

UITableViewTouch.h:

#import <UIKit/UIKit.h> 

@interface UITableViewTouch : UITableView 

@end 

UITableViewTouch.m:

#import "UITableViewTouch.h" 

@implementation UITableViewTouch 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesBegan:touches withEvent:event]; 
    [[self nextResponder] touchesBegan:touches withEvent:event]; 
} 

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesCancelled:touches withEvent:event]; 
    [[self nextResponder] touchesCancelled:touches withEvent:event]; 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesEnded:touches withEvent:event]; 
    [[self nextResponder] touchesEnded:touches withEvent:event]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    [super touchesMoved:touches withEvent:event]; 
    [[self nextResponder] touchesMoved:touches withEvent:event]; 
} 

@end 
1

स्विफ्ट संस्करण क्योंकि मैं तो बस यह बहुत ही इस मुद्दे था:

import UIKit 

class BubbleTouchesTableView: UITableView { 

    // Designed to bubble up touches from a UITableView 

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { 
     super.touchesBegan(touches, withEvent: event) 
     self.nextResponder()?.touchesBegan(touches, withEvent: event) 
    } 

    override func touchesCancelled(touches: NSSet, withEvent event: UIEvent) { 
     super.touchesCancelled(touches, withEvent: event) 
     self.nextResponder()?.touchesCancelled(touches, withEvent: event) 
    } 

    override func touchesEnded(touches: NSSet, withEvent event: UIEvent) { 
     super.touchesEnded(touches, withEvent: event) 
     self.nextResponder()?.touchesEnded(touches, withEvent: event) 
    } 

    override func touchesMoved(touches: NSSet, withEvent event: UIEvent) { 
     super.touchesMoved(touches, withEvent: event) 
     self.nextResponder()?.touchesMoved(touches, withEvent: event) 
    } 

} 
संबंधित मुद्दे