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

}

 

转载于:https://www.cnblogs.com/Always-LuoHan/p/5289828.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值