UIday0902:UITableView 1 按iphone的设置项首页简单布局,点击具体项只需要把该项标题值传过去即可。

用UITableView 按iphone的设置项首页简单布局,点击具体项只需要把该项标题值传过去即可。

AppDelegate.m

#import "AppDelegate.h"
#import "RootViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    RootViewController * rootVC = [[RootViewController alloc]init];
    
    UINavigationController * rootNC = [[UINavigationController alloc]initWithRootViewController:rootVC];
    
    self.window.rootViewController = rootNC;
    
    
    return YES;
}

@end 

RootViewController.m

#import "RootViewController.h"
#import "RootView.h"
#import "Settings.h"
#import "NextViewController.h"

@interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)RootView * rv;

@property(nonatomic,strong)NSMutableArray * dataArray;
@property(nonatomic,strong)NSMutableArray * groupNameArray;

@end

@implementation RootViewController

-(void)loadView{
    self.rv = [[RootView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = _rv;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.rv.tableView.delegate = self;
    self.rv.tableView.dataSource = self;
    
    self.dataArray = [NSMutableArray array];
    
    
    
    Settings * s1 = [[Settings alloc]init];
    s1.name = @"General";
    s1.img = @"01.png";
    Settings * s2 = [[Settings alloc]init];
    s2.name = @"Privacy";
    s2.img = @"02.png";
    Settings * s3 = [[Settings alloc]init];
    s3.name = @"iCloud";
    s3.img = @"03.png";
    Settings * s4 = [[Settings alloc]init];
    s4.name = @"Maps";
    s4.img = @"04.png";
    Settings * s5 = [[Settings alloc]init];
    s5.name = @"Sarari";
    s5.img = @"05.png";
    Settings * s6 = [[Settings alloc]init];
    s6.name = @"Photos & Camera";
    s6.img = @"06.png";
    Settings * s7 = [[Settings alloc]init];
    s7.name = @"Game Center";
    s7.img = @"07.png";
    Settings * s8 = [[Settings alloc]init];
    s8.name = @"Twitter";
    s8.img = @"08.png";
    Settings * s9 = [[Settings alloc]init];
    s9.name = @"Facebook";
    s9.img = @"09.png";
    Settings * s10 = [[Settings alloc]init];
    s10.name = @"Flicker";
    s10.img = @"10.png";
    Settings * s11 = [[Settings alloc]init];
    s11.name = @"Vimeo";
    s11.img = @"11.png";
    Settings * s12 = [[Settings alloc]init];
    s12.name = @"Developer";
    s12.img = @"12.png";
    
    NSMutableArray * a1 = [NSMutableArray array];
    [a1 addObject:s1];
    [a1 addObject:s2];
    NSMutableArray * a2 = [NSMutableArray array];
    [a2 addObject:s3];
    [a2 addObject:s4];
    [a2 addObject:s5];
    [a2 addObject:s6];
    [a2 addObject:s7];
    NSMutableArray * a3 = [NSMutableArray array];
    [a3 addObject:s8];
    [a3 addObject:s9];
    [a3 addObject:s10];
    [a3 addObject:s11];
    NSMutableArray * a4 = [NSMutableArray array];
    [a4 addObject:s12];
    
    [self.dataArray addObject:a1];
    [self.dataArray addObject:a2];
    [self.dataArray addObject:a3];
    [self.dataArray addObject:a4];
    
    self.groupNameArray = @[@"A",@"B",@"C",@"D"].mutableCopy;
    
    self.navigationItem.title = @"settings";
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//    NSLog(@"%ld",[self.dataArray[section] count]);
    return [self.dataArray[section] count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"cell"];
    }
    
    Settings * temp = self.dataArray[indexPath.section][indexPath.row];
    
    cell.textLabel.text = temp.name;
    cell.imageView.image = [UIImage imageNamed:temp.img];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.groupNameArray.count;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NextViewController * nextVC = [[NextViewController alloc]init];
    Settings * s = self.dataArray[indexPath.section][indexPath.row];
    nextVC.astring = [NSString stringWithFormat:@"%@",s.name];
    [self.navigationController pushViewController:nextVC animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end

NextViewController.h

#import <UIKit/UIKit.h>

@interface NextViewController : UIViewController

@property(nonatomic,strong)NSString * astring;

@end

NextViewController.m

#import "NextViewController.h"

@interface NextViewController ()

@property(nonatomic,strong)UILabel * label;

@end

@implementation NextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor greenColor];
    
    self.label = [[UILabel alloc]initWithFrame:CGRectMake(50, 80, 250, 50)];
    self.label.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:_label];
}

-(void)viewWillAppear:(BOOL)animated{
    self.label.text = self.astring;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

RootView.h

#import <UIKit/UIKit.h>

@interface RootView : UIView

@property(nonatomic,strong)UITableView * tableView;

@end

RootView.m

#import "RootView.h"

@implementation RootView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self p_setupViews];
    }
    return self;
}

-(void)p_setupViews{
    self.backgroundColor = [UIColor grayColor];
    
    self.tableView = [[UITableView alloc]initWithFrame:self.bounds style:(UITableViewStyleGrouped)];
    
    [self addSubview:_tableView];
}

@end

Settings.h

#import <Foundation/Foundation.h>

@interface Settings : NSObject

@property(nonatomic,copy)NSString * name;
@property(nonatomic,copy)NSString * img;

@end

Settings.m   默认不做增加或修改




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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值