1.建立乙個viewcontroller,
new file->cocoa touch->objective-c class->class:viewcontroller,subclass of:uiviewcontroller
2.開啟xib,在view中新增tableview,並將tableview的兩個屬性拖到file's owner中,
可以設定tableview的分割槽樣式,選擇style
3.viewcontroller.h:
4.viewcontroller.m:#import @inte***ce newviewcontroller : uiviewcontroller@property (retain, nonatomic) iboutlet uitableview *tableview;
@property(retain,nonatomic)nsdictionary *dic;
@property(retain,nonatomic)nsarray *keys;
@end
#import "newviewcontroller.h"
@inte***ce newviewcontroller ()
@end
@implementation newviewcontroller
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil
return self;
}- (void)viewdidload
//tableview有多少分割槽
-(nsinteger)numberofsectionsintableview:(uitableview *)tableview
//每個分割槽對應多少行
-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section
-(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath
int section = [indexpath section];
int row = [indexpath row];
nsstring *key = self.keys[section];
nsarray *arr = [self.dic objectforkey:key];
cell.textlabel.text = arr[row];
return cell;
}//在每個分割槽上顯示什麼內容
-(nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section
- (void)didreceivememorywarning
//設定索引
-(nsarray *)sectionindextitlesfortableview:(uitableview *)tableview
@end
iOS tableView效能優化
什麼時候呼叫 每當有乙個cell進入視野範圍內就會呼叫 uitableviewcell tableview uitableview tableview cellforrowatindexpath nsindexpath indexpath 3.覆蓋資料 cell.textlabel.text nss...
iOS tableView 上下偏移
說一下問題吧,xcode10 向下相容到ios8,ios10以下版本會出現tableview向上或者向下偏移很是煩人。於是山寨了乙個解決方案 該方法適用於向上偏移 void tableview uitableview tableview willdisplaycell uitableviewcell...
iOS tableView刪除操作
tableview.delegate self void tableview uitableview tableview didselectrowatindexpath nsindexpath indexpath uitableviewdatasource協議中定義的方法。該方法的返回值決定某行是否...