//
//  myTableViewController.h
//  MyTableViewTest1
//
//  Created by UEC on 28/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface myTableViewController : UITableViewController

@property NSArray *names;
@property NSArray *tels;
@property NSArray *photos;

@end
_________________
//
//  myTableViewController.m
//  MyTableViewTest1
//
//  Created by UEC on 28/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "myTableViewController.h"
#import "myViewController.h"

@interface myTableViewController ()

@end

@implementation myTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.names = @[@"Peter",@"Mary",@"Tom",@"Jack"];
    self.tels = @[@"99009900",@"77886677",@"33445566",@"6655455"];
    self.photos = @[@"face1.png",@"face2.png",@"face3.jpg",@"face4.jpg",@"face5.png",@"face6.jpg"];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// TableView Method 1 - Report how many sections it has

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

// TableView Method 2 - Report how many rows it has
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.names.count;
}

// TableView Method 3 - Return the content of each cell or row
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    // Get a new cell based on the name configured in the storyboard
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
    //Give some content to the cell
    long rowNum = [indexPath row];
    
    cell.textLabel.text = self.names[rowNum];
    cell.detailTextLabel.text = self.tels[rowNum];
    cell.imageView.image = [UIImage imageNamed:self.photos[rowNum]];

    
    
    // NSString *myString = [NSString stringWithFormat:@"Testing %li",rowNum];
    // cell.textLabel.text = myString;
    return cell;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    long selectedRowNum = [[self.tableView indexPathForSelectedRow]row];
    myViewController *controller = (myViewController *)[segue destinationViewController];
    controller.receivedName = self.names[selectedRowNum];
    controller.receivedTel = self.tels[selectedRowNum];
    controller.receivedPhoto = self.photos[selectedRowNum];

}

@end
__________________
//
//  myViewController.h
//  MyTableViewTest1
//
//  Created by UEC on 28/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface myViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *telLabel;
@property (weak, nonatomic) IBOutlet UIImageView *photoView;

@property NSString *receivedName;
@property NSString *receivedTel;
@property NSString *receivedPhoto;

@end

________________
//
//  myViewController.m
//  MyTableViewTest1
//
//  Created by UEC on 28/9/16.
//  Copyright (c) 2016年 Unisoft. All rights reserved.
//

#import "myViewController.h"

@interface myViewController ()

@end

@implementation myViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.nameLabel.text = self.receivedName;
    self.telLabel.text = self.receivedTel;
    self.photoView.image = [UIImage imageNamed:self.receivedPhoto];

    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
_________________