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

  • 相关阅读:
    并查集
    CCF201604-02
    作业八
    作业七
    数据结构--链队列基本操作
    数据结构--栈的基本操作
    eclipse配置maven
    软件架构
    scala lambda 表达式 & spark RDD函数操作
    spark(3)
  • 原文地址:https://www.cnblogs.com/hjl553155280/p/6007494.html
Copyright © 2011-2022 走看看