프로그래밍 방식으로 Segue를 수행하고 매개 변수를 대상보기로 전달
내 응용 프로그램에는 프로그래밍 방식으로 segue를 수행하는 버튼이 있습니다.
- (void)myButtonMethod
{
//execute segue programmatically
[self performSegueWithIdentifier: @"MySegue" sender: self];
}
대상보기를 참조하고 일부 매개 변수를 전달하는 방법이 있는지 알고 싶습니다.나는
prepareForSegue
방법에서 그것을 참조 할 수 있다는 것을 알고
myDestinationViewController *vc = [segue destinationViewController];
있지만, 프로그래밍 방식으로 segue를 실행하는 방법을 모르겠습니다.당신은 어떤 아이디어가 있습니까?감사합니다, yassa
최신 정보:이 질문에 대해 죄송합니다 !!! segue가 프로그래밍 방식으로 호출 되더라도
prepareForSegue
메소드가 어쨌든 호출되므로 동일한 일반적인 방식으로 매개 변수를 전달할 수 있음을 발견했습니다.
답은 단순히 segue가 어떻게 트리거되는지 차이가 없다는 것입니다.이
prepareForSegue:sender:
메소드는 어떤 경우에도 호출되며 여기에서 매개 변수를 전달합니다.
오래된 질문이지만 여기에 원하는 것을 수행하는 방법에 대한 코드가 있습니다. 이 경우 테이블 뷰의 선택된 셀에서 다른 뷰 컨트롤러로 데이터를 전달합니다.trget 뷰의 .h 파일에서 :
@property(weak, nonatomic) NSObject* dataModel;
.m 파일에서 :
@synthesize dataModel;
dataModel
할 수있다
string
,
int
또는이 경우처럼 많은 항목이 포함 된 모델입니다
- (void)someMethod {
[self performSegueWithIdentifier:@"loginMainSegue" sender:self];
}
또는...
- (void)someMethod {
UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"HomeController"];
[self.navigationController pushViewController: myController animated:YES];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"storyDetailsSegway"]) {
UITableViewCell *cell = (UITableViewCell *) sender;
NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
NSDictionary *storiesDict =[topStories objectAtIndex:[indexPath row]];
StoryModel *storyModel = [[StoryModel alloc] init];
storyModel = storiesDict;
StoryDetails *controller = (StoryDetails *)segue.destinationViewController;
controller.dataModel= storyModel;
}
}
스위프트 4 :
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ExampleSegueIdentifier" {
if let destinationVC = segue.destination as? ExampleSegueVC {
destinationVC.exampleString = "Example"
}
}
}
스위프트 3 :
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "ExampleSegueIdentifier" {
if let destinationVC = segue.destinationViewController as? ExampleSegueVC {
destinationVC.exampleString = "Example"
}
}
}
한곳에서 segue를 수행하고 segue 준비를 위해 매개 변수를 보내도록 상태를 유지하는 문제를 이해합니다.나는 이것을하는 방법을 알아 냈습니다. 카테고리를 사용하여 userInfoDict라는 속성을 ViewControllers에 추가했습니다. 그리고 나는 보낸 사람이 스스로 (컨트롤러 자체를 의미하는) 방식으로 식별자로 segue를 수행하는 것을 무시했습니다. 이 userInfoDict를 다음 ViewController에 전달합니다.
Here instead of passing the whole UserInfoDict you can also pass the specific params, as sender and override accordingly.
1 thing you need to keep in mind. don't forget to call super method in ur performSegue method.
In case if you use new swift version.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "ChannelMoreSegue" {
}
}
'programing' 카테고리의 다른 글
여러 열에 대한 DISTINCT 계산 (0) | 2020.05.23 |
---|---|
자동 레이아웃을 사용하여 UIScrollview에서 제약 조건을 설정하려면 어떻게해야합니까? (0) | 2020.05.23 |
TFS가 최신 버전이 아닌 이유는 무엇입니까? (0) | 2020.05.23 |
maven-release-plugin으로 테스트를 건너 뛰려면 어떻게해야합니까? (0) | 2020.05.21 |
Maven 관리 종속성을 위해 Eclipse에 첨부 된 소스 jar 파일 가져 오기 (0) | 2020.05.21 |