iOS開發系列

2021-12-29 16:21:13 字數 2608 閱讀 1809

ios開發系列 ---- ui (自定義tableview)。本章實現效果:

我們使用mvc架構來實現自定義tableview,具體的mvc介紹請自行百度,在本章中不作為主要內容講解。

model層:

datasource.h

#import

@inte***ce datasource : nsobject

+ (nsarray *)getuserinfo;

@end

datasource.m

#import "datasource.h"

@implementation datasource

+ (nsarray *)getuserinfo

@end

view層:customtableviewcell.h

#import

@inte***ce customtableviewcell : uitableviewcell

@property (nonatomic, strong) uilabel * labelname;//姓名

@property (nonatomic, strong) uilabel * labelnum; //手機號

@end

customtableviewcell.m

#import "customtableviewcell.h"

@implementation customtableviewcell

//重寫初始化方法:將控制項新增到單元格上,如果將子檢視控制項新增到cell上 借助contenview檢視,這樣的話cell上子檢視會隨著cell的變化而變化

- (instancetype)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier

return self;

}- (void)awakefromnib

- (void)setselected:(bool)selected animated:(bool)animated

@end

viewcontroller層:viewcontroller.m

#import "viewcontroller.h"

#import "datasource.h"

#import "customtableviewcell.h"

#import "twoviewcontroller.h"

@inte***ce viewcontroller ()<

uitableviewdatasource,

uitableviewdelegate>

@property (nonatomic, strong) nsmutablearray *arrayds;

@property (nonatomic, strong) uitableview *tableview;

@end

@implementation viewcontroller

- (void)viewdidload

- (void)setupdatas

- (void)setupsubviews

#pragma mark - uitableviewdatasource

- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section

- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath

cell.labelname.text = [[self.arrayds objectatindex:indexpath.row] objectforkey:@"personname"];

cell.labelnum.text = [[self.arrayds objectatindex:indexpath.row] objectforkey:@"phonenum"];

return cell;

} else

cell.textlabel.text = [[self.arrayds objectatindex:indexpath.row] objectforkey:@"phonenum"];

return cell;

}}- (void)viewwillappear:(bool)animated

- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath

- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath

@end

自定義**檢視demo(內含plist檔案)

iOS開發系列文章

ios開發系列的文章,內容循序漸進,包含c語言 objc ios開發以及日後要寫的遊戲開發和swift程式設計幾部分內容。文章會持續更新,希望大家多多關注,如果文章對你有幫助請點贊支援,多謝!ios開發系列 c語言之基礎知識 ios開發系列 c語言之陣列和字串 ios開發系列 c語言之指標 ios開...

系列 iOS開發 NSDictionary

系列 ios開發 nsdictionary 繼續介紹oc中的另外一種資料型別 字典 nsdictionary 首先nsdictionary和陣列是差不多的 區別是陣列的每一項就是每一下,但是字典的每一項是兩個東西key和value 這兩個是一一對應的,即key value的形式 另外字典裡面只能儲存...

自學iOS開發系列 OC(block)

1.block 塊語法,是一種新的語法結構。學習的時候可以模擬於函式指標。2.block和函式指標對比 import 宣告函式 int add int,int int main int argc,char argv nslog d block 3,6 實現函式 int add int a,int b...