ios開發中最簡單的tableview使用一
再任何移動開發中list列表的展示是不可缺少的,這裡首先講到的是如何在ios中實現最簡單的list列表展示,後面還會講到自定義列表的展示
穿件xib檔案,拖入tableview控制元件執行後沒有任何資料保證每個步驟都沒問題
1、在標頭檔案中繼承<UITableViewDataSource,UITableViewDelegat>
宣告要重寫的兩個方法:-(NSInteger)tableView:(UITalbeView *)tableView numberOfRowsInSection:(NSInteger)section;
-(UITableViewCell *)tableview:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
2、實現這兩個方法
第一在方法體中放入return self.datasource.count;
第二個方法體中放入:
static NSString *[email protected]"cell";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellIndentifier forIndexPath:indexPath];
if(cell==nil){
cell=[UITableViewCell alloc]initWithStyle:UITableCellStyleDefalut reuseIdenfifier:CellIdentifier];
}
[email protected]"dhj";
return cell;
標紅字體表示使用的是預設的列表格式,還有其他格式入圖片標題詳情的佈局格式這個網上可以查查,過程中如果發現有單詞錯誤,請見諒畢竟是手敲擊的,mac本連線不上外網智慧靠手敲擊了。最後給cell賦值時可以集合上一篇文章內容用物件獲取資料後再用物件把值給cell