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
原文地址:https://www.cnblogs.com/zhangqing979797/p/13466934.html