![](/img/trans.png)
[英]how to use delegate to pass data to from one View Controller to another?
[英]How to pass data from one view to another view controller in IOS?
我正在使用Xcode 4.3.1 。 我使用具有許多視圖控制器的Storyboard創建了UI。
問題
在我的應用程序中,我正在使用ShakeGesture。 搖晃時,我正在執行一些操作,其工作正常。 但是,當搖動停止時,我需要將一些值傳遞給另一個View控制器以顯示它。 我看到過很多帖子,說如何在單擊按鈕時傳遞值,但是沒有人與我的問題有關。
如果您解決我的問題,那就太好了
我的問題是
搖動后如何將值從一個View傳遞到另一個View控制器?
我正在尋找任何示例或教程。 非常感激。
編輯
上述問題的確切函數
我在First View Controller中有一個按鈕
當按鈕觸發時,它將彈出帶有一些數據的pickerview。 當用戶選擇它時,選擇器值將替換按鈕值。
然后搖動發生在它停止時,我必須將數據傳遞給其他視圖控制器。
碼
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake)
{
// I need to pass data here. Thats i am confusing
}
}
謝謝你們的幫助
通過ctrl從情節提要中的第一個視圖控制器拖動到第二個視圖控制器來創建序列。 單擊segue並轉到身份檢查器(按command-option-3)。 在標識符字段中為其命名,例如“ Shaking Stopped”。 然后在您的運動終止方法中使用...
[self performSegueWithIdentifier:@"Shaking Stopped" sender:self];
這將使視圖切換到第二個視圖。 然后在准備segue時將其更改為...(當然使用您自己的值)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"Shaking Stopped"]) {
<The Second View Controller> *controller = segue.destinationViewController
//change your values in the other view controller here
controller.someValue = self.someValue //an example
若要檢測搖晃手勢的結束,請在視圖控制器中實現motionEnded:withEvent。
- (void) motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (event.type == UIEventSubtypeMotionShake)
{
// perform the seque
}
}
使用上述技術將數據傳遞到此視圖控制器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.