標籤:des style color os io 使用 ar for cti
UITableViewDataSource 協議中常用方法
1.設定右邊索引值
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
2.設定分組標識
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
3.設定分組個數
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
4.設定行數
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
5.建立cell(使用重用機制,如下例)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
1.建立重用標識符
staticNSString *identifier =@"reuse”;
2.去重用隊列中根據標識符取可重用的cell
AddressBookCell *cell = [tableViewdequeueReusableCellWithIdentifier:identifier];
3.判斷是否擷取到可重用的cell(最後要空間釋放)
if (!cell) {
cell = [[[AddressBookCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:identifier]autorelease];
}
return cell;
}
6.設定tableView的每一行的編輯狀態(YES,可編輯)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES
}
7.edit按鈕的點擊事件(當點擊edit按鈕時觸發)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
8.當提交編輯操作時觸發
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
9.設定tableView每一行是否允許移動(YES,可移動)
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES
}
10.提交移動操作之後觸發
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
UITableViewDelegate協議中常用方法
1.設定行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 55;
}
2.選中cell時觸發
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
3.設定tableViewCell的編輯樣式(插入/刪除)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
4.設定當點擊編輯按鈕時上面顯示的文字,如顯示刪除
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPathNS_AVAILABLE_IOS(3_0) { return@"刪除"; }
5.設定cell移動的位置
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
iOS ,UITableViewDataSource 和 UITableViewDelegate協議中常用方法