I'm trying to write an iPhone app. When the user presses the OK button, I want the message from the textview to be saved in a UIPicker of a开发者_StackOverflow中文版nother ViewController. How can I do this? Can anyone provide some sample code or link to a tutorial?
Here you are,
-(void) contentToDisplay: (NSString *)content { localVariableToController = content; assignToPicker = content; }
have a method in your another viewController and assign the text while creating controller like
[yourAnotherController contentToDisplay:@"YourTextToUseinotherController"]
Hope this helps.
Use the below code as reference
When you press the OK button,let's suppose the below function is called.
-(void) buttonpressed:(id) sender
{
[myAnotherController DisplayInPickerControl:myTextview.text];
}
in AnotherController.mm implement DisplayInPickerControl
functions.
-(void) DisplayInPickerControl:(NSString*) string
{
//Add `string` into your data structure (Data structure may be an array used for holding the value for picker view)
[myNSmutableArray insertObject:string atIndex:0];
OR
[myNSmutableArray addObject:string];
//Now use UIPickerView's `reloadComponent:` function ...
[myPickeerView reloadComponent:0];//Reloads a particular component of the picker view.
OR
[myPickeerView reloadAllComponents];//Reloads all components of the picker view.
}
if you are populating your piker with an array in another view controller then you have update that array when you press ok. For this you have to make that array as a property of your another viewController and when you press ok then update that array by accessing it as viewController.array
you should have @protocol protocol - name (with SendMessage method) in controller , and this delegate will be extended by pickercontroller to where you want to send message.
u can call method using .
[ delegate SendMessage:@"your text"];
精彩评论