2011-06-07 8 views
7

मैं एक यूआईपीकर व्यू दिखाना चाहता हूं जब मैं एक बटन दबाता हूं (कीबोर्ड की तरह) और फिर जब उपयोगकर्ता स्क्रीन पर कहीं भी टैप करता है तो चले जाओ। मैं यह कैसे कर सकता हूँ? धन्यवाद।मैं कीबोर्ड की तरह एक पिकर व्यू कैसे पेश कर सकता हूं?

थोड़ा और पृष्ठभूमि: मेरे पास UITextFiewCell में महीनों नामक UITextField है। अब मेरे लिए सबसे अच्छा विकल्प एक UIPikcerView डालना है और उपयोगकर्ता को इसे टाइप करने के बजाय महीने को चुनना आसान होगा (और यह बेहतर तरीका है)। लेकिन UIPickerView एक UITableViewCell में वास्तव में बदसूरत दिखता है, उल्लेख नहीं है कि मैं इसका विशाल आकार नहीं बदल सकता। तो इस मामले में मुझे क्या करना चाहिए?

+0

आपका शीर्षक बहुत वर्णनात्मक नहीं है। – Julian

+0

इसके बारे में क्षमा करें, जो आप प्राप्त करने की कोशिश कर रहे हैं, उसके बारे में अधिक जानकारी प्रदान करें। शीर्षक किसी और द्वारा अपडेट किया गया था, लेकिन अब मैंने इस प्रश्न के लिए और अधिक पृष्ठभूमि प्रदान की है। – sumderungHAY

उत्तर

13

इस प्रकार आपको UITickView में टेक्स्टफ़िल्ल्ड के लिए UIPickerView का उपयोग करना चाहिए।

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    cell.selectionStyle= UITableViewCellSelectionStyleNone; 
    UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)]; 
    textField.clearsOnBeginEditing = NO; 
    textField.textAlignment = UITextAlignmentRight; 
    textField.delegate = self; 
    [cell.contentView addSubview:textField]; 
    //textField.returnKeyType = UIReturnKeyDone; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 

     // if you want a UIPickerView for first row... then do the following // 
     // Here.. packSizePickerView is an object of UIPickerView 

    if (indexPath.row == 1) 
    { 
    textField.tag=0; 
    textField.delegate= self; 
    packSizePickerView.delegate = self; 
    packSizePickerView = [[UIPickerView alloc] init]; 
    packSizePickerView.autoresizingMask=UIViewAutoresizingFlexibleWidth; 
    packSizePickerView.showsSelectionIndicator=YES; 
    textField.inputView = packSizePickerView; 
    } 

    // if you want to select date/months in row 2, go for UIDatePickerView // 

    if (indexPath.row == 1) 
    { 
     textField.tag = 1; 
     UIDatePicker *datePicker = [[UIDatePicker alloc] init]; 
     datePicker.datePickerMode = UIDatePickerModeDate; 
     [datePicker addTarget:self action:@selector(datePickerValueChangedd:) forControlEvents:UIControlEventValueChanged]; 
     datePicker.tag = indexPath.row; 
     textField.delegate= self; 
     textField.inputView = datePicker; 
     [datePicker release]; 

    } 

} 

// Configure the cell... 

NSInteger row = [indexPath row]; 
cell.textLabel.text = [myArray objectAtIndex:row]; 

return cell; 

}

और datePickerValueChangedd

- (void)datePickerValueChangedd:(UIDatePicker*) datePicker{ 
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 68, 68)]; 
NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
df.dateStyle = NSDateFormatterMediumStyle; 
label.text = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]]; 

    NSLog(@"I am inside the datePickerValueChanged - - %@", label.text); 
[df release]; 
    globalValue1 = label.text; 

    // use a global variable to copy the value from the pickerView. // 
    }  

अब textFieldDidEndEditing में के लिए:

-(void) textFieldDidEndEditing:(UITextField *)textField { 
if (textField.tag ==0) 
    [textField setText: globalValue0]; 

if (textField.tag ==1) 
    [textField setText: globalValue1]; 

} 

और UIDatePicker इस्तीफा देने के लिए, एक UIControl के रूप में UIView सेट और

resignFirstResponder 
+0

महान उत्तर !! यही वही है जो मैं खोज रहा था !! +1 – Garoal

0

मुझे लगता है कि आपको देखने योग्य स्क्रीन के बाहर अपने यूआईपीकर व्यू को "बाहर" रखना होगा और बटन दबाए जाने पर इसे एनिमेट करना होगा। मुझे सच में यकीन नहीं है कि इससे छुटकारा पाने का सबसे अच्छा तरीका क्या होगा, लेकिन जब संभवतः पिकर दिखाई देता है तो आप पैरेंट दृश्य पर एक टैप सुन सकते हैं और फिर इसे वापस एनिमेट कर सकते हैं।

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

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