Reputation: 13
I'm new to the x-code word, and i need your help.
I'm trying to write a code to show and hide the UIpickerview.
the Uipickerview must show when i press the select button in the view controller,and hide when i press the done button in the toolbar and then show the selected data in a label
this is my code..
this is the .h file
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
<UIPickerViewDelegate,UIPickerViewDataSource>
{
IBOutlet UIPickerView *NumExamPicker;
NSMutableArray *NumExamName;
}
@property (weak, nonatomic) IBOutlet UILabel *lbout;
@property (strong, nonatomic) IBOutlet UIView *PickerContainer;
- (IBAction)SelectButton:(id)sender;
- (IBAction)DoneButton:(id)sender;
@end
and this is my .m file
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize lbout;
@synthesize PickerContainer;
- (void)viewDidLoad
{
[super viewDidLoad];
NumExamName = [[NSMutableArray alloc] init];
[NumExamName addObject:@"One"];
[NumExamName addObject:@"Two"];
[NumExamName addObject:@"Three"];
[NumExamName addObject:@"Four"];
PickerContainer.frame = CGRectMake(0, 600, 320, 206);
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [NumExamName count];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
lbout.text = [NumExamName objectAtIndex:row];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction)SelectButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
PickerContainer.frame = CGRectMake(0, 362, 320, 206);
[UIView commitAnimations];
}
- (IBAction)DoneButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
PickerContainer.frame = CGRectMake(0, 600, 320, 206);
[UIView commitAnimations];
}
@end
when i run the simulator, it crashes and stops at this method:
// main.m
// showandhideuipickerview
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I don't know how to solve it.
oh one more thing, I'm working with one single view, will it be the same if i want it not to be the fist view? or should i add more code.
thanks...
Upvotes: 1
Views: 122
Reputation: 2414
Pls add this delegate method of UIPickerView
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow: (NSInteger)row forComponent: (NSInteger)component {
return [NumExamName objectAtIndex:row];
}
Upvotes: 1