重写表格

//AppDelegate.m

ViewController *theVc = [[ViewController alloc]init];

UINavigationController *theNav = [[UINavigationController alloc]initWithRootViewController:theVc];

//添加标题

theVc.title = @"菜单";

self.window.rootViewController = theNav ;


//ViewController.m

#import "ViewController.h"

#import "MyTableViewCell.h"

@interface ViewController (){

NSDictionary *theDic;

}

@property(nonatomic,strong)UITableView *theTable ;

@end

@implementation ViewController

-(UITableView *)theTable

{

if (!_theTable)

{

_theTable  = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20) style:UITableViewStylePlain];

_theTable.delegate = self ;

_theTable.dataSource = self ;

_theTable.rowHeight = 80 ;

}

return _theTable;

}

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self.view addSubview:self.theTable];

NSString *path = [[NSBundle mainBundle]pathForResource:@"My list" ofType:@"plist"];

theDic = [NSDictionary dictionaryWithContentsOfFile:path];

}

#pragma -

#pragma mark -UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return theDic.allKeys.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"celled"];

if (!cell) {

cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"celled"];

}

NSString *key = [theDic.allKeys objectAtIndex:indexPath.row];

NSArray *arr = [theDic objectForKey:key];

cell.theImage.image = [UIImage imageNamed:arr[0]];

cell.theL1.text = key ;

cell.theL2.text = arr[1];

cell.theL3.text = arr[2];

cell.theL4.text = arr[3];

cell.theL5.text = arr[4];

return cell ;

}

//MyTableViewCell.h

#import@interface MyTableViewCell : UITableViewCell

@property(nonatomic,strong)UIImageView *theImage ;

@property(nonatomic,strong)UILabel *theL1,*theL2,*theL3,*theL4,*theL5 ;

@end

//MyTableViewCell.m

#import "MyTableViewCell.h"

@implementation MyTableViewCell

//懒加载模式  使用下划线

-(UIImageView *)theImage

{

if (!_theImage) {

_theImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 80, 80)];

[_theImage.layer setCornerRadius:80/2];

_theImage.layer.masksToBounds = YES ;

//添加到视图

[self addSubview:self.theImage];

}

return _theImage ;

}

//UILab懒加载

-(UILabel*)theL1

{

if (!_theL1) {

_theL1 = [[UILabel alloc]initWithFrame:CGRectMake(85, 5, 160, 30)];

//添加到视图

[self addSubview:self.theL1];

}

return _theL1 ;

}

-(UILabel*)theL2

{

if (!_theL2) {

_theL2 = [[UILabel alloc]initWithFrame:CGRectMake(85, 25, 160, 30)];

//添加到视图

[self addSubview:self.theL2];

}

return _theL2 ;

}

-(UILabel*)theL3

{

if (!_theL3) {

_theL3 = [[UILabel alloc]initWithFrame:CGRectMake(85,45, 160, 30)];

//添加到视图

[self addSubview:self.theL3];

}

return _theL3 ;

}

-(UILabel*)theL4

{

if (!_theL4) {

_theL4 = [[UILabel alloc]initWithFrame:CGRectMake(255, 5, 160, 30)];

//添加到视图

[self addSubview:self.theL4];

}

return _theL4 ;

}

-(UILabel*)theL5

{

if (!_theL5) {

_theL5 = [[UILabel alloc]initWithFrame:CGRectMake(305, 45, 160, 30)];

//添加到视图

[self addSubview:self.theL5];

}

return _theL5 ;

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 用cocoaPods配置第三方文件 第一步。打开终端 第二步。cd+文件夹 第三步。pod init 第四步。打开...
    不说谎的匹诺曹Y阅读 4,809评论 0 1
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 7,311评论 1 14
  • 哦吼吼,又研究了几天,把FMDB这个封装好的数据库搞定了,写了个简单的例子,基于FMDB的添删改查操作,界面很一般...
    lichengjin阅读 3,630评论 0 0
  • 作者唯一QQ:228544117。。。。。 =========后面的都要新建一个文章 AppDelegate.h ...
    CC_iOS阅读 4,652评论 0 0
  • iOS开发系列--网络开发 概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博、微信等,这些应用本身可...
    lichengjin阅读 9,120评论 2 7