나는 UIViewController
이고 UITableViewController
입니다.
ViewController에서 UIButton
과 UITextfield
이 있는데, 버튼을 누르면(iPhone 5S, iPhone 6, iPhone 6S, iPhone 7)과 같은 tableview의 정적 데이터로 이동합니다. ViewController의 텍스트 필드에 표시됩니다. 시도했지만 이것을 얻을 수 없습니다. 이 문제를 해결하도록 도와주세요. 아래에있는 내 코드입니다 :테이블 뷰에서 뷰 컨트롤러 텍스트 필드로 데이터를 다시 전달 목표 - C
ViewController.h
————————————————
#import <UIKit/UIKit.h>
#import "Utility.h"
@interface ViewController : UIViewController
- (IBAction)oneButtonClicked:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *txtOne;
ViewController.m
————————————————
//Can't understand what to do in this viewcontroller.
TableViewController.h
—————————————————————-
#import <UIKit/UIKit.h>
#import "Utility.h"
@interface FamilyDetailsViewController : UITableViewController
@end
TableViewController.m
—————————————————————-
#import "FamilyDetailsViewController.h"
@interface FamilyDetailsViewController()
{
NSArray *arr;
}
@end
@implementation FamilyDetailsViewController
- (void)viewDidLoad {
[super viewDidLoad];
arr=[[NSArray alloc]initWithObjects:@"Parent",@"Grandparent",@"Sibling",@"Child",@"Other", nil];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arr count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[arr objectAtIndex:indexPath.row];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController popViewControllerAnimated:YES];
}
는 참조 파일
ViewControllerB.m
에서 http://stackoverflow.com/questions/19343519/pass- data-back-to-previous-viewcontroller – suhit충분히 검색 한 후 질문을 게시하십시오. 귀하의 문제에는 수천 가지 해결책이 있습니다. [This] (http://stackoverflow.com/questions/626898/how-do-i-create-delegates-in-objective-c) 도움이 될 것입니다. – iPeter
맞춤형 프로토콜은 피터가 링크와 suhit의 대답을 제공 할 때 viewcontrollers간에 데이터를 전달하는 가장 좋은 방법입니다. –