zoukankan      html  css  js  c++  java
  • 表视图单元格事件用nib和storyboard的两种写法总结

    一.代码的写法比较
     
    ViewController.m

    nib写法
    #pragma mark - 实现表视图委托方法
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSInteger row = [indexPath row];
       
        CitiesViewController *citiesViewController = [[CitiesViewController alloc] initWithStyle:UITableViewStylePlain];
        NSString *selectName = [self.listData objectAtIndex:row];
        citiesViewController.listData = [self.dictData objectForKey:selectName];
        citiesViewController.title = selectName;
        [self.navigationController pushViewController:citiesViewController animated:YES];

    }

    storyboard写法
    //选择表视图行时候触发
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
       
        if([segue.identifier isEqualToString:@"ShowSelectedProvince"])
        {
            CitiesViewController *citiesViewController = segue.destinationViewController;
            NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
            NSString *selectName = [self.listData objectAtIndex:selectedIndex];
            citiesViewController.listData = [self.dictData objectForKey:selectName];
            citiesViewController.title = selectName;
        }
    }

    CitiesViewController.m
    nib写法
    #pragma mark - 实现表视图委托方法
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSInteger row = [indexPath row];
       
        DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
       
        NSDictionary *dict = [self.listData objectAtIndex:row];
       
        detailViewController.url = [dict objectForKey:@"url"];
        NSString *name = [dict objectForKey:@"name"];
        detailViewController.title = name;
        [self.navigationController pushViewController:detailViewController animated:YES];
       
    }
    storyboard写法
    //选择表视图行时候触发
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
         
        if([segue.identifier isEqualToString:@"ShowSelectedCity"])
        {
            DetailViewController *detailViewController = segue.destinationViewController;
           
            NSInteger selectedIndex = [[self.tableView indexPathForSelectedRow] row];
            NSDictionary *dict = [self.listData objectAtIndex:selectedIndex];
           
            detailViewController.url = [dict objectForKey:@"url"];
           
            NSString *name = [dict objectForKey:@"name"];
            detailViewController.title = name;
        }
    }

  • 相关阅读:
    图解CSS3----1-关系选择器
    HTML5----热区(在图片img上第一超链接选区)
    Javascript----练习二(运算符)
    Javascript----练习一(变量)
    PHP表单
    maven
    Docker
    PHP字符串
    面向对象思想的核心概念
    虚方法
  • 原文地址:https://www.cnblogs.com/hjl553155280/p/6007494.html
Copyright © 2011-2022 走看看