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

    }

  • 相关阅读:
    MySql和oracle的不同
    Session的有效期设置
    WebSocket和WebRtc的一些心得
    Spring事务管理
    Tomcat下使用war包发布项目
    Log4j记日志功能
    javascript typeof和instanceof
    js模块化的意义
    有关call和apply的理解。
    h5滑动插件(包含幻灯片滑动逻辑)
  • 原文地址:https://www.cnblogs.com/Always-LuoHan/p/5289828.html
Copyright © 2011-2022 走看看