OC plist重寫單元格

一 創(chuàng)建一個(gè)plist文件,并添加一些分組的名稱巍糯,如下圖所示

屏幕快照 2017-09-03 下午8.40.03.png

二 先創(chuàng)建一個(gè)繼承于UITableViewCell的文件,命名為 MyTableViewCell.

在.h中文件中,定義一些屬性

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


在.m中寫懶加載方法

//懶加載模式  使用下劃線
-(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 ;
    
}

在ViewController.m文件中 書寫具體的代碼

#import "ViewController.h"
#import "MyTableViewCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    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 ;
    
}

在AppDelegate.m寫一個(gè)導(dǎo)航欄

導(dǎo)入頭文件

#import "ViewController.h"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    ViewController *theVc = [[ViewController alloc]init];
    UINavigationController *theNav = [[UINavigationController alloc]initWithRootViewController:theVc];
    //添加標(biāo)題
    theVc.title = @"菜單";
    
    self.window.rootViewController = theNav ;
    

    return YES;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末瓷们,一起剝皮案震驚了整個(gè)濱河市你弦,隨后出現(xiàn)的幾起案子燎孟,更是在濱河造成了極大的恐慌禽作,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,546評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件揩页,死亡現(xiàn)場離奇詭異旷偿,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)爆侣,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,224評論 3 395
  • 文/潘曉璐 我一進(jìn)店門萍程,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人兔仰,你說我怎么就攤上這事茫负。” “怎么了乎赴?”我有些...
    開封第一講書人閱讀 164,911評論 0 354
  • 文/不壞的土叔 我叫張陵忍法,是天一觀的道長。 經(jīng)常有香客問我榕吼,道長饿序,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,737評論 1 294
  • 正文 為了忘掉前任友题,我火速辦了婚禮嗤堰,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己踢匣,他們只是感情好告匠,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,753評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著离唬,像睡著了一般后专。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上输莺,一...
    開封第一講書人閱讀 51,598評論 1 305
  • 那天戚哎,我揣著相機(jī)與錄音,去河邊找鬼嫂用。 笑死型凳,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的嘱函。 我是一名探鬼主播甘畅,決...
    沈念sama閱讀 40,338評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼往弓!你這毒婦竟也來了疏唾?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,249評論 0 276
  • 序言:老撾萬榮一對情侶失蹤函似,失蹤者是張志新(化名)和其女友劉穎槐脏,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體撇寞,經(jīng)...
    沈念sama閱讀 45,696評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡顿天,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,888評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了重抖。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片露氮。...
    茶點(diǎn)故事閱讀 40,013評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡祖灰,死狀恐怖钟沛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情局扶,我是刑警寧澤恨统,帶...
    沈念sama閱讀 35,731評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站三妈,受9級特大地震影響畜埋,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜畴蒲,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,348評論 3 330
  • 文/蒙蒙 一悠鞍、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧模燥,春花似錦咖祭、人聲如沸掩宜。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,929評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽牺汤。三九已至,卻和暖如春浩嫌,著一層夾襖步出監(jiān)牢的瞬間檐迟,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,048評論 1 270
  • 我被黑心中介騙來泰國打工码耐, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留追迟,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,203評論 3 370
  • 正文 我出身青樓骚腥,卻偏偏與公主長得像怔匣,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子桦沉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,960評論 2 355

推薦閱讀更多精彩內(nèi)容