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;
        }
    }

  • 相关阅读:
    [转]PYTHON-SCRAPY-WINDOWS下的安装笔记
    [转]Scrapy入门教程
    [转]Centos 6.5 安装 Scrapy 0.22.2成功
    Python的三个常用内置函数
    sublime连接Python的使用
    tornado-options(3)
    配置 PPP 封装和认证
    交换机验证 PVST 实验
    vlan间通信配置vtp模式
    convert expdp dmp file to SQL DDL statements
  • 原文地址:https://www.cnblogs.com/hjl553155280/p/6007494.html
Copyright © 2011-2022 走看看