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

}

 

posted @ 2016-03-17 22:45  A唯爱永生_罗韩  阅读(177)  评论(0编辑  收藏  举报