• UI26 UITableView


    app.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* root =[[RootViewController alloc]init];
        UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:root];
        
        nav.navigationBar.barTintColor=[UIColor greenColor];
        nav.navigationBar.translucent=NO;
        
        self.window.rootViewController=nav;
          
        return YES;
    }

    root.m

    #import "RootViewController.h"
    
    @interface RootViewController ()<UITableViewDataSource,UITableViewDelegate>
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        UITableView *tab=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667-64) style:UITableViewStylePlain];
        [self.view addSubview:tab];
        
        tab.delegate=self;
        tab.dataSource=self;
    
    }
    
    //UITableView 代理方法
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        //1.创建静态标识符
        static NSString *identifier =@"cell";
        //2.根据标识符从重用池中取cell
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        //3.如果没有取到就创建一个新的
        if (cell==nil){
            NSLog(@"进来了");
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifier];
        
        }
        //对cell进行赋值
        cell.textLabel.text=@"老罗";
        
        cell.detailTextLabel.text=@"老罗这个人很屌";
        cell.imageView.image=[UIImage imageNamed:@"tianmao"];
        
        cell.accessoryType=UITableViewCellAccessoryDetailButton;
        
    //    cell.accessoryView=
        
        
        return cell;
        
        
    }
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 20;
    }
    
    //cell的高度
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        
        return 60;
        
    }
    
    
    @end
  • 相关阅读:
    POJ3259 Wormholes
    leetCode-Plus One
    leetCode-Pascal's Triangle
    leetCode-Longest Continuous Increasing Subsequence
    leetCode-Missing Number
    leetCode-Maximum Product of Three Numbers
    leetCode-Image Smoother
    leetCode-Contains Duplicate
    机器学习实战笔记-使用Apriori算法进行关联分析
    leetCode-Degree of an Array
  • 原文地址:https://www.cnblogs.com/zhangqing979797/p/13466934.html
Copyright © 2020-2023  润新知