標籤:
如果有需要跟蹤NSArray中的內容,需要重寫descriptionWithLocal 方法。首先建立一個NSArray 的Category,在建立出來的.m檔案中加入下列代碼
- (NSString *)descriptionWithLocal:(id)local
{
NSMutableString *string = [NSMutableString string];
[string appendString:@"("];
for (id obj in self) {
[string appendFormat:@"\n\t\"%@\",", obj];
}
[string appendString:@"\n)"];
return string;
}
如此一來,用NSLog顯示NSArry中的資料不再是utf-8編碼,顯示為原來資料。
UITableView
需要一個資料來源來顯示資料
1.需加入資料來源協議 UITableViewDataSource ; <
2. 設定表格的組數 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView ; <
3.設定每個分組中的行數 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section ; <
4.設定每個分組中顯示的資料內容 - (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPaht:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIndentifier:nil];
indexPath.section 即為分組名
} cell即是返回的分組中的資料。
5.設定分組的標題 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSIntger)secton ; <
6.設定頁尾的標題, 分組底部的子標題 - (NSString *)tableView:(UITableVIew *)tableView titleForFooterInSection:(NSInteger)section ; <
7.字典返回所有keys的方法 NSArray *items = [self.cities allKeys]; < 裡面資料出來的順序是亂的
8.將UITableView中的分組分開(即設定style,但style只能在初始化的時候設定)
UITableView *tableView = [[UITableView alloc] initWithFrame: style:(UITableViewStyle)] ; <
9.代理方法: - (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndex *)indexPaht ; <
細節決定成敗!
IOS學習筆記(三)TableVIew