2011-01-28 15 views
9

हम UIKeyboardTypeNumberPad को कैसे कार्यान्वित कर सकते हैं ताकि इसमें 'किया' बटन होगा? डिफ़ॉल्ट रूप से यह एक नहीं है।UIKeyboardTypeNumberPad बिना किए गए बटन के

+0

आप कीबोर्ड को लागू करने से क्या मतलब है, आप कीबोर्ड या किसी भी बात ईएलएसएस को छिपाना चाहते हैं। – Ishu

+0

नहीं ... बस कीबोर्ड – Abhinav

+1

में कोई किया गया बटन नहीं होगा प्रिय नंबर पैड में कोई पूर्ण बटन नहीं है। इसलिए आपका प्रश्न मान्य नहीं है। – Ishu

उत्तर

13

यदि मैं गलत नहीं हूं तो आप UIKeyboardTypeNumberPad के लिए कीबोर्ड पर कस्टम "पूर्ण" बटन जोड़ने के तरीके के बारे में पूछना चाहते हैं। उस मामले में यह सहायक हो सकता है। एक UIButton * donebutton in.h घोषित करने और फ़ाइल मीटर करने के लिए

- (void)addButtonToKeyboard { 
    // create custom button 
    if (doneButton == nil) { 
     doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)]; 
    } 
    else { 
     [doneButton setHidden:NO]; 
    } 

    [doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; 
    // locate keyboard view 
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
    UIView* keyboard = nil; 
    for(int i=0; i<[tempWindow.subviews count]; i++) { 
     keyboard = [tempWindow.subviews objectAtIndex:i]; 
     // keyboard found, add the button 
     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) { 
      if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
       [keyboard addSubview:doneButton]; 
     } else { 
      if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
       [keyboard addSubview:doneButton]; 
     } 
    } 
} 

- (void)doneButtonClicked:(id)Sender { 
//Write your code whatever you want to do on done button tap 
//Removing keyboard or something else 
} 

मैं अपने आवेदन और बटन के फ्रेम में ही उपयोग कर रहा हूँ निम्नलिखित कोड जोड़ने के इस प्रकार समायोजित कर रहे हैं, आप इस प्रकार कॉल कर सकते हैं [स्वयं addButtonToKeyboard] जब भी आप कीबोर्ड पर किए गए बटन को दिखाने की आवश्यकता है। UIKeyboardTypeNumberPad में अन्यथा कोई पूर्ण बटन नहीं है। enter image description here

+0

मुझे लाइन UIWindow * tempWindow = [[[UIAplplication sharedAplication] windows] objectAtIndex: 1] के साथ कोई समस्या है; मुझे कोई सबव्यूज़ – user784625

+0

के साथ एएमटी सरणी मिलती है जहां आपको रिक्त सरणी मिलती है। स्क्रीन पर मौजूद कीबोर्ड के मामले में आपको निश्चित रूप से कीबोर्ड के लिए सरणी में कम से कम एक आइटम मिल जाएगा। –

+0

मैंने कीबोर्ड फ़िलशो और कीबोर्डडिडशो में एक बार इस फ़ंक्शन में कॉल जोड़ा है लेकिन मुझे अभी भी खाली सरणी मिलती है – user784625

1

आईओएस 5 अंक हल हो गया। बहुत - बहुत धन्यवाद।

मुझे पूर्ण बटन प्रदर्शित करने में कोई समस्या थी।

बदला:

if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
    [keyboard addSubview:doneButton]; 

जो iOS 5 में किया बटन प्रदर्शित नहीं किया ...

के साथ:

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) { 
    if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
     [keyboard addSubview:doneButton]; 
} else { 
    if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
     [keyboard addSubview:doneButton]; 
} 

इलाज में काम किया। तुम एक सितारा हो। धन्यवाद, निकोला ;-)

1

अगर किसी को भी कोई समस्या है कि एक ही ऐप में अन्य प्रकार के कीबोर्ड लोड करने का प्रयास करते समय डोन बटन पॉप-अप रहता है, तो मुझे पता है कि इस समस्या के बहुत से ऐप्स हैं। वैसे भी, मैंने यह कैसे हल किया है: आपके व्यू कंट्रोलर में (उसी व्यू कंट्रोलर जिसे आपने जोड़ा गया बटन जोड़ा) इस कोड को जोड़ें (जैसा है) और इसे फिर से दिखने के साथ अपनी समस्याओं को हल करना चाहिए। उम्मीद है कि यह कुछ लोगों को मदद करता है।

- (void)viewWillDisappear:(BOOL)animated { 
[super viewWillDisappear:animated]; 
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) { 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil]; 

} else { 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 
} 

}

2
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardDidShowNotification object:nil]; 


//Call this method 

- (void)keyboardWillShow:(NSNotification *)note { 


    UIButton *doneButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)]; 
    doneButton.adjustsImageWhenHighlighted = NO; 
    [doneButton setImage:[UIImage imageNamed:@"Done.png"] forState:UIControlStateNormal]; 
    [doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside]; 
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; 
    UIView* keyboard; 
    for(int i=0; i<[tempWindow.subviews count]; i++) { 
     keyboard = [tempWindow.subviews objectAtIndex:i]; 

     if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) { 
      if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES) 
       [keyboard addSubview:doneButton]; 
     } 
     else { 
      if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES) 
       [keyboard addSubview:doneButton]; 
     } 
    } 

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