代码改变世界

storyBoard

2015-10-16 05:17  真实16  阅读(209)  评论(0编辑  收藏  举报

 

#import "ViewController.h"

#import "HomeViewController.h"

 

@interface ViewController ()<UITextFieldDelegate>

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    self.title = @"登录";

    self.accTextField.delegate = self;

    self.pswTextField.delegate = self;

 

 

 

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (IBAction)tapAction:(id)sender {

    [self.accTextField resignFirstResponder];

    [self.pswTextField resignFirstResponder];

    

}

 

- (IBAction)buttonAction:(id)sender {

    [self.accTextField resignFirstResponder];

    [self.pswTextField resignFirstResponder];

    

    if ([_pswTextField.text isEqualToString:@"888"]) {

        NSLog(@"登录成功");

        

        

        

        

//      在storyBoard 里面已经 [[HomeViewController alloc] init] 一次了,如果这里再初始化一次,就会造成 hvc “再次初始化”

//        HomeViewController *hvc = [[HomeViewController alloc] init];

//        [self.navigationController pushViewController:hvc animated:YES];

        

        

//        HomeViewController 的视图控制器 可以通过 storyboard 里面的 Identifier 标记 找到对应的视图控制器

        

//        1、 需要找到 使用的storyBoard

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

        

//        2、在storyBoard 里找到 刚才设置好标记的视图控制器

        HomeViewController *vc = [storyboard  instantiateViewControllerWithIdentifier:@"HomeViewController"];

        [self.navigationController pushViewController:vc animated:YES];

    }

    

    

 

}

@end

#import "HomeViewController.h"

#import "DetailViewController.h"

 

@interface HomeViewController ()<UITableViewDataSource, UITableViewDelegate>

{

    NSArray *allList;

}

@end

 

@implementation HomeViewController

- (void)viewDidAppear:(BOOL)animated {

    

    

    

    [self viewDidLoad];

}

- (void)viewDidLoad {

    [super viewDidLoad];

 

    self.tableView.delegate = self;

    self.tableView.dataSource = self;

    NSArray *imageList = @[@"stomach_33.jpg", @"scratch_09.jpg", @"高清图1.jpg", @"高清图2.jpg", @"高清图1.jpg", @"scratch_09.jpg", @"stomach_33.jpg", @"高清图2.jpg"];

    NSArray *nameList = @[@"悟空1", @"悟空2", @"悟空3", @"悟空4", @"悟空5", @"悟空6", @"悟空7", @"悟空8"];

    NSArray *contentList = @[@"蹦出来了", @"大闹地狱府,修改生死簿", @"闹东海,抢棒子", @"闹天宫,搅盛会", @"齐天大圣,横空出世", @"被压五指山~~~", @"被压五指山~~~~~~~~~~~", @"还压五指山~~~~~~~~~~~~~~^-^"];

    allList = @[imageList, nameList, contentList];

   }

 

 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    

    

//     在storyBoard里面已经初始化了 Cell 所以不用再次初始化

//    Identifier 一定要和 storyBoard里面添加的 identitifier一致

    if (indexPath.row == 0) {

        

        NSString *identifier = @"idcell";

        UITableViewCell *idcell = [tableView dequeueReusableCellWithIdentifier:identifier];

       

    return idcell;

    }

    NSString *identifier = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

 

    

    

    

    UIImageView *imageV = (UIImageView *)[cell.contentView viewWithTag:100];

    UILabel *nameLabel = (UILabel *)[cell.contentView viewWithTag:101];

    UILabel *contentLabel = (UILabel *)[cell.contentView viewWithTag:102];

    

    imageV.image = [UIImage imageNamed:allList[0][indexPath.row-1]];

    nameLabel.text = allList[1][indexPath.row-1];

    contentLabel.text = allList[2][indexPath.row-1];

    

        return cell;

    

}

 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 9;

}

 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row != 0) {

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

        DetailViewController *vc= [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];

        vc.info = @{@"title":allList[1][indexPath.row], @"content":allList[2][indexPath.row]};

        [self.navigationController pushViewController:vc animated:YES];

    }

}