#import <UIKit/UIKit.h>
#import "FirstTableViewController.h"
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *table;
@property(strong,nonatomic) NSArray *arr;
@end
#import <UIKit/UIKit.h>
#import "FirstTableViewController.h"
@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) UITableView *table;
@property(strong,nonatomic) NSArray *arr;
@end
#import <UIKit/UIKit.h>
@interface FirstTableViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic)NSArray *arr;
@property(strong,nonatomic)UITableView *table;
@property(strong,nonatomic)NSString *str;
@end
#import "FirstTableViewController.h"
@interface FirstTableViewController ()
@end
@implementation FirstTableViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 设置导航栏的前景色
self.navigationController.navigationBar.barTintColor=[UIColor grayColor];
// 设置导航栏字体颜色和大小
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:30]}];
// 设置标题
self.title=self.str;
// 初始化Table
self.table=[[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
// 设置分隔符的颜色
self.table.separatorColor=[UIColor redColor];
// 设置代理
self.table.delegate=self;
self.table.dataSource=self;
[self.view addSubview:self.table];
// 设置唯一标识
[self.table registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
//行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifi=@"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifi forIndexPath:indexPath];
cell.textLabel.text=self.arr[indexPath.row][@"city"];
return cell;
}