2012-01-04 12 views
5

मेरे पास एक यूआईपीकर व्यू है और इसे आईपैड में यूआईएक्शनशीट के अंदर दिखाने की ज़रूरत है (यह आईपैड में नहीं, आईफोन में बहुत सीधी काम करता है)।आईपैड में UIActionSheet के अंदर UIPickerView जोड़ना

- (IBAction) buttonPressed:(id)sender 
{ 
    NSLog(@"I am pressed"); 

    UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)]; 
    picker.delegate = self; 
    picker.dataSource = self; 
    picker.showsSelectionIndicator = YES; 
    [self.view addSubview:picker];  
} 

// PickerView प्रतिनिधि और डेटा स्रोत कार्य::

// returns the number of 'columns' to display. 
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1; 
} 

// returns the # of rows in each component.. 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
    return 5; 
} 

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    return @"One"; 
} 

लेकिन जब परिवर्तन ऊपर

मैं पर मैं निम्नलिखित कोड निष्पादित जब मैं देखें क्लिक करें पर एक बटन है एक एक्शनशीट के अंदर पिकर व्यू जोड़ने के लिए कोड, यह केवल एक्शनशीट का शीर्षलेख दिखाता है लेकिन इसके अंदर पिकर व्यू के बिना! इस प्रकार

संशोधित कोड:

- (IBAction) buttonPressed:(id)sender 
{ 
    NSLog(@"I am pressed"); 

    UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:@"My PickerView" 
               delegate:nil 
            cancelButtonTitle:nil 
           destructiveButtonTitle:nil 
            otherButtonTitles:nil]; 

    UIPickerView* picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,200,500,500)]; 
    picker.delegate = self; 
    picker.dataSource = self; 
    picker.showsSelectionIndicator = YES; 

    [actionSheet addSubview:picker]; 
    [actionSheet showFromRect:CGRectMake(0, 0, 320, 469) inView:self.view animated:NO]; 

} 

उत्तर

4

मैं बेकार करता हूं, मैं UIPopoverController का उपयोग UITableViewController के बजाय इसके अंदर करूँगा! .. फिर भी धन्यवाद!

1

कोशिश पिकर के फ्रेम को संशोधित करने के लिए। (100, 200) पर (एक्स, वाई) एक अच्छी स्थिति नहीं हो सकती है।

+0

जब मैंने पिकर व्यू इनिटलाइन को 'UIPickerView * picker = [[UIPickerView alloc] initWithFrame में बदल दिया: CGRectMake (0,0,320,469)]; 'अब मैं एक्शनशीट के अंदर पिकर व्यू का बहुत छोटा हिस्सा देख सकता हूं लेकिन एक्शनशीट दिखाया गया है एक बहुत छोटे वर्ग के रूप में, मैं इसे बड़ा कैसे बना सकता हूं, मैं अपनी चौड़ाई और ऊंचाई को बदलने की कोशिश कर रहा हूं लेकिन काम नहीं कर रहा है! –

+0

यह देखने के लिए कि क्या आकार बदलता है, रद्द करने के लिए कुछ NSString को रद्द करें बटन को सेट करने का प्रयास करें। –

+0

मैं बेकार हूं, मैं इसके बजाय 'UITableViewController' के साथ' UIPopoverController' का उपयोग करूंगा! .. फिर भी धन्यवाद! –

-4

मुझे लगता है कि लाइन ([actionSheet addSubview:picker];) होना चाहिए [actionSheet addSubview:picker.view];
मैं एक ही समस्या हो रही थी, लेकिन UIWindow का उपयोग कर।

+0

'UIPickerView '' UIView' से विरासत में आता है; इसमें अपनी संपत्ति नहीं है, 'व्यू' है। – Olie

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