OC实现个人中心页面

AppDelegate.m:

 1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
 2     // Override point for customization after application launch.
 3     //创建窗口
 4     self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
 5     //设置窗口的根控制器
 6     mainViewController *mainVC = [[mainViewController alloc]init];
 7     self.window.rootViewController = mainVC;
 8     //显示窗口
 9     [self.window makeKeyAndVisible];
10     return YES;
11 }

mainViewController.m:

 1 @interface mainViewController ()<UITableViewDataSource,UITableViewDelegate>
 2 {
 3     UITableView *personalTableView;
 4     NSArray *dataSource;
 5 }
 6 
 7 @end
 8 
 9 @implementation mainViewController
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     // Do any additional setup after loading the view.
14     personalTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
15     [self.view addSubview:personalTableView];
16     personalTableView.dataSource = self;
17     personalTableView.delegate = self;
18     personalTableView.bounces = NO;//yes,就是滚动超过边界会反弹有反弹回来的效果; NO,那么滚动到达边界会立刻停止。
19     personalTableView.showsVerticalScrollIndicator = NO;//不显示右侧滑块
20     personalTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;//分割线
21     dataSource = @[@"我的分享",@"密码管理",@"用户协议",@"关于"];
22 }
23 
24 #pragma mark - TbaleView的数据源代理方法实现
25 //返回组数的代理方法
26 -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
27     return 3;
28 }
29 //返回行数的代理方法
30 -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
31     if (section==0){
32         return 1;
33     }else if (section==1){
34         return dataSource.count;
35     }else{
36         return 1;
37     }
38 }
39 //每个分组上边预留的空白高度
40 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
41     return 20;
42 }
43 //每个分组下边预留的空白高度
44 -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
45     if (section==2){
46         return 40;
47     }
48     return 20;
49 }
50 //每个分组下对应的tableView高度
51 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
52     if(indexPath.section == 0){
53         return 80;
54     }
55     return 40;
56 }
57 //返回每一行Cell的代理方法
58 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
59     // 1 初始化Cell
60     // 1.1 设置Cell的重用标识
61     static NSString *ID = @"cell";
62     // 1.2 去缓存池中取Cell
63     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
64     // 1.3 若取不到便创建一个带重用标识的Cell
65     if (cell == nil){
66         cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
67     }
68     
69     if (indexPath.section==0) {
70         cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"userinfo"];
71         
72         UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(12, 10, 60, 60)];
73         imageView.image = [UIImage imageNamed:@"1578945"];
74         [cell.contentView addSubview:imageView];
75         
76         UILabel *nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 0, 60, 80)];
77         nameLabel.text = @"小燕子";
78         [cell.contentView addSubview:nameLabel];
79         
80     }else if (indexPath.section==1){
81         cell.textLabel.text = [dataSource objectAtIndex:indexPath.row];
82         //设置Cell右边的小箭头
83         cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
84         
85     }else{
86         cell.textLabel.text = @"退出登录";
87         cell.textLabel.textAlignment = NSTextAlignmentCenter;
88     }
89     
90     //设置Cell右边的小箭头
91     //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
92     return cell;
93 }
94 
95 - (void)didReceiveMemoryWarning {
96     [super didReceiveMemoryWarning];
97     // Dispose of any resources that can be recreated.
98 }
99 @end

效果图:

 

posted @ 2015-09-18 11:07  AbelSu  阅读(561)  评论(0编辑  收藏  举报