ViewController1에서 버튼을 클릭 할 때 나타나는 팝업 테이블 뷰 (ViewController2)가 있습니다. 그런 다음 테이블에서 행을 선택하면 해당 값을 ViewController1로 다시 보내야합니다. 나는 NSDictionary를 설정했다. 그것은 정상적인 탐색 컨트롤러에서 잘 작동하지만 dismissModalViewControllerAnimated를 사용하여 테이블 뷰를 다시 내려 놓으려고하면 데이터가 첫 번째 뷰에 표시됩니다.팝업 테이블 뷰에서 NSDictionary 데이터를 반환하십시오.
이 내가 생각 여기이 질문에 유사합니다
ViewController1.h : 여기 http://www.iphonedevsdk.com/forum/iphone-sdk-development/39995-return-data-dismissmodalviewcontrolleranimated.html
내 코드입니다
@protocol ViewController1Delegate;
@interface ViewController1 : UIViewController <ViewController2Delegate> {
id <ViewController1Delegate> delegate;
}
@property (nonatomic, assign) id <ViewController1Delegate> delegate;
@end
@protocol ViewController1Delegate
- (void)viewController1DidFinish:(ViewController1 *)controller;
@end
ViewController1.m :
-(void)buttonGoToViewController2 {
ViewController2 *controller = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
// this controller.delegate = self causes it to crash if i have it uncommented for some reason...
// controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}
ViewController2.m :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(searching) {
// Navigation logic may go here. Create and push another view controller.
NSDictionary *selectedCountry = [self.copyListOfItems objectAtIndex:indexPath.row];
ViewController1 *dvController = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil andDictionary: selectedCountry];
NSLog(@"selected hit this %@",selectedCountry);
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
[self dismissModalViewControllerAnimated:YES];
}
else {
// Navigation logic may go here. Create and push another view controller.
NSDictionary *dictionary = [self.listOfItems objectAtIndex:indexPath.row];
ViewController1 *dvController = [[ViewController1 alloc] initWithNibName:@"ViewController1" bundle:nil andDictionary: dictionary];
NSLog(@"normal hit this %@",dictionary);
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
}
}
그래서 내 ViewController2 didSelectRowAtIndexPath에서 이와 같은 것이 있습니까? \t'ViewController1Delegate * appDelegate = (ViewController1Delegate *) [[UIApplication sharedApplication] delegate]; \t NSString * nodeText = [[listOfItems objectAtIndex : indexPath.row] objectForKey : @ "station"]; \t NSString * passThis = [appDelegate nodeText]; ' \t 그런 다음 내 ViewController1에는 다음과 같은 것이 있습니까? \t'ViewController1Delegate * appDelegate = (ViewController1Delegate *) [[UIApplication sharedApplication] delegate]; \t PassedString = [appDelegate passThis]; ' – Aaron
아니, 거의 복잡하지 않습니다. http://iphonedevelopertips.com/objective-c/the-basics-of-protocols-and-delegates.html와 같은 위임자 및 프로토콜에 대한 자습서를 확인하십시오. –