zoukankan      html  css  js  c++  java
  • UITableTableViewController的简单运用

    AppDelegate.h文件

    #import <UIKit/UIKit.h>

    @interface AppDelegate : UIResponder <UIApplicationDelegate>

    @property (strong, nonatomic) UIWindow *window;

    @end

    AppDelegate.m文件

    #import "AppDelegate.h"

    #import "RootTableViewController.h"

    @interface AppDelegate ()

    @end

    @implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Override point for customization after application launch.

        self.window.rootViewController=[[UINavigationController alloc]initWithRootViewController:[[RootTableViewController alloc]initWithStyle:UITableViewStyleGrouped]];

        return YES;

    }

    RootTableViewController.h文件(继承UITableViewController的类)

    #import <UIKit/UIKit.h>

    #import "ViewController.h"

    @interface RootTableViewController : UITableViewController

    @property (strong,nonatomic) NSArray *arrPlist;

    @end

    RootTableViewController.m文件

    #import "RootTableViewController.h"

    @interface RootTableViewController ()

    @end

    @implementation RootTableViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor=[UIColor lightGrayColor];

        self.title=@"省市联动";

        

        //标题颜色

        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]}];

        //导航颜色,前景色

        self.navigationController.navigationBar.barTintColor=[UIColor grayColor];    

        NSString *path=[[NSBundle mainBundle]pathForResource:@"city" ofType:@"plist"];

        self.arrPlist=[NSArray arrayWithContentsOfFile:path];

        

        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuseIdentifier"];

    }

    #pragma mark - Table view data source

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

        return 1;

    }

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

    {

        return self.arrPlist.count;

    }

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

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuseIdentifier" forIndexPath:indexPath];

        cell.textLabel.text=self.arrPlist[indexPath.row][@"State"];

        return cell;

    }

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

    {

        ViewController *view=[[ViewController alloc]init];

        view.arrCity =self.arrPlist[indexPath.row][@"Cities"];

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

    }

  • 相关阅读:
    树莓派学习笔记(三)——远程调试树莓派程序(Pycharm实现)
    树莓派学习笔记(一)——系统安装与远程显示
    记 laravel 排除CSRF验证
    thinkPHP5 生成微信小程序二维码 保存在本地
    微信小程序 rich-text 富文本中图片自适应
    Laravel 中自定义 手机号和身份证号验证
    laravel Excel 导入
    微信小程序之页面跳转(tabbar跳转及页面内跳转)
    关于MySQL事务和存储引擎常见FAQ
    微信小程序点击保存图片到本地相册——踩坑
  • 原文地址:https://www.cnblogs.com/Always-LuoHan/p/5289828.html
Copyright © 2011-2022 走看看