Get selected value of a picker view that is present in different view and use the string in some other view

南笙酒味 提交于 2019-11-28 14:36:52

Step 1: Take a NSString variable in your appDelegate.

Step 2: create instance of appDelegate in your both view were your want to set value and get value as following.

yourApplicationDelegate *appDelegate;

Step 3: init appDelgate in implementation file as following

appDelegate = [[UIApplication sharedApplication] delegate];

after this statement you can use the string variable from both view controller you declared in appDelegate of you application.

That's it. now you can assign value from first view and access it in second view.

KAREEM MAHAMMED

You can declare NSString in Secondview globally and it is better to take a button and in that action You have to write

Take a NSString *selectedString globally in firest view in Pickerview delegate method

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
   selectedString=    [arrayNo objectAtIndex:row];

//here array is the array used for pickerview 
}

-(IBAction)btnAction:(id)sender
{
SecondView *sec=[[SecondView alloc]initWithNibname:@"SecondView" bundle:nil];
sec.stringFromPrevView=selectedString;
[self presentModalViewController:sec animated:YES];
[sec release];
}

stringFromPrevView this string will be use in Your SecondView as per Your requirement

I hope this will helps You

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!