इंटरफ़ेस बिल्डर का उपयोग किये बिना मैं प्रोग्राम में यूआईपीकर व्यू को कैसे देख सकता हूं? यूआईपीकर व्यू के प्रतिनिधि भागों के साथ काम करने के तरीके को समझने में भी परेशानी हो रही है।UIPickerView प्रोग्रामेटिक उदाहरण?
उत्तर
UIPickerView प्रोग्राम के रूप में जोड़ने के लिए:
- (void)pickerView:(UIPickerView *)pV didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component == 1)
selectedRowPicker1 = row;
else if(component == 2)
selectedRowPicker2 = row;
else
selectedRowPicker3 = row;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component == 1)
return [list1 count];
else if(component == 2)
return [list2 count];
else
return [list3 count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if(component == 1)
val1 = [list1 objectAtIndex:row];
else if(component == 2)
val2 = [list2 objectAtIndex:row];
else
val3 = [list3 objectAtIndex:row];
return strTemp;
}
मैं पिकर में 3 घटकों के लिए विभिन्न वस्तुओं की 3 सूचियां कैसे जोड़ूं? मैं प्रति घटक चयनित प्रत्येक आइटम को कैसे पुनर्प्राप्त करूं? धन्यवाद –
मैंने अपना जवाब संपादित कर लिया है। अब आप जांच सकते हैं – AppAspect
मैंने आपको एक बिंदु दिया क्योंकि यह अन्य लोगों के लिंक के लिए कुछ और जानकारी जोड़ता है .... धन्यवाद –
यह आईओएस में काम नहीं करेगा 8
UIPickerView प्रोग्राम के रूप में साथ डेटास्रोत
ज फ़ाइल बनाएँ
@interface PickerViewTestAppViewController : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource> {
UIActionSheet *pickerViewPopup;
UIPickerView *categoryPickerView;
UIPickerView *pickerView;
NSMutableArray *dataArray;
}
@property (nonatomic, retain) UIActionSheet *pickerViewPopup;
@property (nonatomic, retain) UIPickerView *categoryPickerView;
@property (nonatomic, retain) NSMutableArray *dataArray;
@end
मीटर फ़ाइल
@implementation PickerViewTestAppViewController
@synthesize pickerViewPopup,categoryPickerView;
@synthesize dataArray;
- (void)viewDidLoad {
[super viewDidLoad];
// Init the data array.
dataArray = [[NSMutableArray alloc] init];
// Add some data for demo purposes.
[dataArray addObject:@"One"];
[dataArray addObject:@"Two"];
[dataArray addObject:@"Three"];
[dataArray addObject:@"Four"];
[dataArray addObject:@"Five"];
pickerViewPopup = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
categoryPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, 0, 0)];
[categoryPickerView setDataSource: self];
[categoryPickerView setDelegate: self];
categoryPickerView.showsSelectionIndicator = YES;
UIToolbar *pickerToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
pickerToolbar.barStyle = UIBarStyleBlackOpaque;
[pickerToolbar sizeToFit];
UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(categoryDoneButtonPressed)];
UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(categoryCancelButtonPressed)];
[pickerToolbar setItems:@[cancelBtn, flexSpace, doneBtn] animated:YES];
[pickerViewPopup addSubview:pickerToolbar];
[pickerViewPopup addSubview:categoryPickerView];
[pickerViewPopup showInView:self.view];
[pickerViewPopup setBounds:CGRectMake(0,0,320, 464)];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
// Handle the selection
NSLog(@"%@",[dataArray objectAtIndex:row]);
selectedCategory = [NSString stringWithFormat:@"%@",[dataArray objectAtIndex:row]];
}
// tell the picker how many rows are available for a given component
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [dataArray count];
}
// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
// tell the picker the title for a given component
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [dataArray objectAtIndex: row];
}
// tell the picker the width of each row for a given component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
int sectionWidth = 300;
return sectionWidth;
}
-(void)categoryDoneButtonPressed{
categoryLable.text = selectedCategory;
[pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES];
}
-(void)categoryCancelButtonPressed{
[pickerViewPopup dismissWithClickedButtonIndex:1 animated:YES];
}
रेफरी: http://gabriel-tips.blogspot.in/2011/04/uipickerview-add-it-programmatically_04.html
इसे आईओएस 8 में कैसे काम करना है? – user1872384
NSInteger selectCourse=[_coursePicker selectedRowInComponent:0];
NSInteger selectSem=[_coursePicker selectedRowInComponent:1];
NSString *whatCourse=[Course objectAtIndex:selectCourse];
NSString *whatSem=[Sem objectAtIndex:selectSem];
NSString *courses=[[NSString alloc]initWithFormat:@"Course : %@ - %@",whatCourse,whatSem];
[self.selectedCours setTitle:courses forState:UIControlStateNormal];
- 1. UIPickerView
- 2. UIPickerView
- 3. UIPickerView
- 4. UIPickerView
- 5. UIPickerView
- 6. अधिभावी UIPickerView
- 7. UIPickerView reloadData
- 8. UIPickerView फ़ॉन्ट
- 9. javac.exe एएसटी प्रोग्रामेटिक एक्सेस उदाहरण
- 10. UIPickerView कॉलम टाइटल
- 11. UIPickerView ऊंचाई नहीं अस्थिर
- 12. UIPickerView गलत शीर्षक दिखाता है
- 13. बदलने UIPickerView पंक्ति की ऊँचाई
- 14. कस्टम UIPickerView को UINavigationBar में कैसे जोड़ें?
- 15. एक परिपत्र UIPickerView (आईफोन/आईपैड) कैसे बनाएं?
- 16. आप कैसे UIPickerView घटक लपेटते हैं?
- 17. आईपैड में UIActionSheet के अंदर UIPickerView जोड़ना
- 18. UIPickerView पर परिवर्तनों का पता कैसे लगाएं?
- 19. प्रोग्रामेटिक रूप से उदाहरण के सार्वजनिक डीएनएस कैसे प्राप्त करें?
- 20. प्रोग्रामेटिक रूप से RotateAnimations कैसे करें के पूर्ण उदाहरण?
- 21. UIPickerView लोड होने के बाद पंक्ति का चयन करें
- 22. टीसीएल/उदाहरण उदाहरण?
- 23. socket.io उदाहरण दोबारा उदाहरण
- 24. उदाहरण
- 25. उदाहरण()
- 26. उदाहरण
- 27. उदाहरण
- 28. उदाहरण?
- 29. उदाहरण
- 30. उदाहरण
यहाँ है एक अच्छी तरह से प्रलेखित और व्यापक उदाहरण है कि आईओएस में काम करता है 10 https://stackoverflow.com/a/46047257/3634990 – jungledev