代理方法
//設置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}
//Section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3;
}
//設置每個區(qū)有多少行共有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
//設置區(qū)域的名稱
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
{
return @"123";
}
//是否允許行移動
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//響應點擊事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"響應單擊事件");
}
//小按鈕的響應事件
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"accessoryButton的響應事件");
}
//刪除按鈕的名字
-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"刪除";
}
//設置滑動
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
//ruturn NO不實現(xiàn)滑動
return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"手指撮動了");
return UITableViewCellEditingStyleDelete;
// //插入
// return UITableViewCellEditingStyleInsert;
}
//設置CELL的樣式
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
//灰色
cell.selectionStyle = UITableViewCellSelectionStyleGray;
//無顏色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
//向右箭頭樣式
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//向右箭頭button
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
TableView樣式
UITableViewStylePlain //矩形邊緣
UITableViewStyleGrouped //圓角邊緣
單元格樣式
UITableViewCellStyleDefault // img + title
UITableViewCellStyleSubtitle // img + title +subtitle
UITableViewCellStyleValue1, // img +title + subtitle(right)
UITableViewCellStyleValue2, // title + subtitle