Swift UITableView's data show in UIPickerView - uitableview

Hello I am a new beginning for programming,i have search a lot of article but no one can answer my issue so...help me
here is my question
I have already build UITableVIew and PickerView, and Using CoreDate now
I want to let UITableView's data show in UIPickerView(The data is all String)
how to load UITableView's Data put in UIPickerView?
"that two View is different View"

You have to implement UIPickerViewDelegate methods in your picker class. And use this method from protocol for putting UITableView inside:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

Related

How to automate a UIPickerView to select particular item using KIF?

I have a UIPickerView showing some numbers [4,5,6,7,8]. I want to automate picker view to select a number 6. For that i'm trying by using following code.
tester().tapViewWithAccessibilityLabel("height field")// picker view is input view for the text field
tester().waitForViewWithAccessibilityLabel("size picker")
tester().selectPickerViewRowWithTitle("6")
But the test failing with error "the uidatepicker does not have the expected column count". I am unable to solve this issue. Any one help me to solve this issue.
you should add this here:
- (NSString *)pickerView:(UIPickerView *)pickerView accessibilityLabelForComponent:(NSInteger)component
{
return #"height field";
}
The problem which I had was, that I used:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component{
instead of:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
It seems that KIF doesn't support attributed texts to select in a UIPickerView

Is there Number spinner control for ios?

I'm looking for a spinner control something similar to this for ios:
http://github.hubspot.com/odometer/docs/welcome/
can't find anything so far, please share if you know any.
there is one third party library , by which you can do this https://github.com/Rizh/RCounter
https://github.com/naked-apps/NACounter
https://github.com/jonathantribouharet/JTNumberScrollAnimatedView
The nearest thing in iOS, similar to this is UIPickerView. You can create a UIPickerView in the Interface Builder or through code.
Next, make your class conform to UIPickerViewDataSource and UIPickerViewDelegate.
In your viewDidLoad: method, assign the delegate and dataSource of the UIPickerView to the respective class.
And finally add the following methods to your class.
// The number of columns of data
- (int)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 5;
}
// The number of rows of data
- (int)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 10;
}
// The data to return for the row and component (column) that's being passed in
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [NSString stringWithFormat:#"%ul",row];
}

UIPickerView pickerView:titleForRow:rowforComponent method not called

I have a UIPickerView in my storyboard.
The UIViewController containing it has interface declarations set
#interface ContactDetail : UIViewController <ABPeoplePickerNavigationControllerDelegate, UIPickerViewDataSource, UIPickerViewDelegate,UIAlertViewDelegate, UITextFieldDelegate>
on view Load, pickerview delegation set
pickerView_RelationshipType.dataSource=self;
pickerView_RelationshipType.delegate = self;
pickerView_RelationshipType.showsSelectionIndicator = YES;
all UIPickerView datasource and delegate methods are triggered except those 2
pickerView:titleForRow:rowforComponent
and
pickerView:viewForRow:forComponent:reusingView
those following are called, no problem
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
what's in numberOfComponentsInPickerView ?
If your numberOfRows returning 0, then your delegate method will never be called - the picker won't ask for the title of a row if it doesn't think it has any rows to display.
Make sure your data source array is allocated and initialized. I ran into this problem when everything was hooked up correctly (I set the data source and delegates and was conforming to the protocols), but I forgot to initialize my data source arrays before adding objects to them. My code was hitting numberOfComponentsInPickerView and numberOfRowsInComponent but not titleForRow and I couldn't figure out why. Make sure your data source is not returning nil.
Kind of a stupid edge case, but I figured I'd add my answer in case someone else runs into the same issue.

Append 2 webservices data in one uiPickerView component

Here is my Problem, I am sorry if it is a very frequent question.
I had a web-service from which I was getting projects and Holidays from different methods. Now I just want this Holidays and projects to be loaded into the uipickerview in a single component.
For example I had my projects with names proj1, proj2,proj3 which is coming from getProjects method from web-service.
Similarly I had holidays with names sickleave, casual leave which is coming from getHolidays method from web-service.
So I want in such a way that sickleave,casual leave,proj1,proj2 to be displayed in a single component in a uipickerview
I guess somehow some answers were stating to use NSMutableArray, But I dont know how to use that...
I think you should follow these steps:
Declare and initialize an NSMutableArray.
Use addObject method on your NSMutableArray to add objects in your array from both WebServices. You will be required to loop through till the WebServices are returning values.
Outside of your loop use: [picker reloadAllComponents]
Use picker view delegate methods as:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [yourArray count];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1 ;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [yourArray objectAtIndex:row];
}
Also don't forget to connect your picker view delegate and datasource.

iOS UIPickerView how to get the selected row outside the delegate method

I know the UIPickerView has this method:
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
But inside this method, I want to get the selected row of other components. How on Earth can I do that?
You can get selected row number anywhere by using selectedRowInComponent method of UIPickerView.
Such like
NSString *YourselectedTitle = [self.yourArrayName objectAtIndex:[self.yourPickerName selectedRowInComponent:0]];
NSLog(#"%#", YourselectedTitle);
Old question but if someone like me is working with Swift 2.0 now the answer is
let row = self.myPicker.selectedRowInComponent(0)
let value = myArray[row]
I wrote 0 to component value because my picker has only one component, but it could have more than one such as datepicker with Date and Time
You can even use this method outside the function that you were talking about if you keep an outlet of your pickerview

Resources