I have a UIViewController
and a UITableViewController
.
In ViewController I have a UIButton
and UITextfield
, when I press button it will navigate to TableViewController
with static data in the tableview like (iPhone 5S, iPhone 6, iPhone 6S, iPhone 7), when I select any of the row it should be displayed in the textfield of ViewController. Tried but cannot get this one. Help me to solve this. below is my code:
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];
}