---------------------------------------------------------------------------
1 呼叫 2 出來
[self performSegueWithIdentifier:@"upload to location" sender:nil];
---------------------------------------------------------------------------
1 傳送data到 2
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
id dv = segue.destinationViewController;
[dv setValue:@"123,111" forKey:@"gps"];
}
---------------------------------------------------------------------------
---------------------------------------------------------------------------
2 返回 1 (不透過nav bar 的back button)
UIViewController *prevVC = [self.navigationController.viewControllers objectAtIndex:1];//1 is level
[self.navigationController popToViewController:prevVC animated:YES];
指定回去的leval,1就是leavl
---------------------------------------------------------------------------
2 傳送data回 1 (需要實作delegate)
step1 :(在page2的.h檔定義delegate)
//--delegate部分
@protocol page2Delegate <NSObject>
@optional
- (void)passValue:(NSString *)value;
@end
//--
//--
@property (nonatomic, weak) id<LocationDelegate> delegate;
//--
---------------------------------------------------------------------------
step2 : 在page1裡載入delegate
#import "page2.h"//實作協定用
@interface uploadViewController : UIViewController<page2Delegate>
- (void)passValue:(NSString *)value{
//在這裡實作協定
}
---------------------------------------------------------------------------
strp3:在pag1呼叫page2時,指定自己是page2的delegate
strp3:在pag1呼叫page2時,指定自己是page2的delegate
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
id dv = segue.destinationViewController;
[dv setValue:self forKey:@"delegate"];
}
---------------------------------------------------------------------------
step4 :在page2適當的call method,讓delegate執行這個method
[self.delegate passValue:@"pass from 2 data string"];
/*
UIStoryboard *storybord = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
locationViewController *uploadView = [storybord instantiateViewControllerWithIdentifier:@"location"];
[self.navigationController pushViewController:uploadView animated:YES];
*/
沒有留言:
張貼留言