2012-02-23 7 views
5

क्या एक्सकोड में पिकर व्यू को डिफ़ॉल्ट पंक्ति पर शुरू करने का कोई तरीका है? अभी, मेरी पिकर व्यू मेरी सरणी में पहले तत्व पर शुरू होती है।एक्सकोड: पिकर व्यू को एक निश्चित पंक्ति में कैसे शुरू करें जब इसे पहली बार प्रदर्शित किया गया है

तो उदाहरण के लिए, यदि मेरे पास 30 पंक्तियों वाला 1 घटक है, तो मैं पिकर व्यू को 15 पंक्ति पर कैसे शुरू कर सकता हूं जब उपयोगकर्ता पहली बार पिकर व्यू देखता है?

धन्यवाद

उत्तर

9

उपयोग - [UIPickerView selectRow: inComponent: एनिमेटेड:] ... यह सोचते हैं आप एक घटक है, निम्न करें:

UIPickerView *aPicker = [[[UIPickerView alloc] init] autorelease]; 
aPicker.delegate = self; 
aPicker.dataSource = self; 
aPicker.showsSelectionIndicator = YES; 
[self.view addSubview:aPicker]; 
[aPicker selectRow:14 inComponent:0 animated:NO]; 
0

आप selectedrow के रूप में नामित एक चर आवंटित करने के लिए है जो आपके व्यूडिडलोड में डिफ़ॉल्ट मान 0 है। i.e. int seletedrow = 0;

_pickerView=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 43, 320, 480)]; 
    _pickerView.delegate=self; 
    _pickerView.dataSource=self; 
    _pickerView.backgroundColor=[UIColor whiteColor]; 
    [_pickerView selectRow:selectedrow inComponent:0 animated:NO]; 
    [_pickerView setShowsSelectionIndicator:YES];  
: कोड जहां PickerView initialising कर रहे हैं निम्नलिखित

- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent: (NSInteger)component 
{ 

    selectedrow=row; 

} 

और आखिरी लिखने में:

उसके बाद निम्न UIPickerView के didSelectRow विधि में, कर

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

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