#import
@interface RootViewController : UIViewController <</b>UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, retain) UITableView *myTableView;
@property (nonatomic, retain) UITableViewCell *tableViewCell;
@property (nonatomic, retain) NSMutableArray *tableViewDataSource; // TableView中显示的数据
@property (nonatomic, retain) NSMutableArray *tableViewDateSource2; // 第二个分组使用的数据
@end
// 主要的方法有如下,
#pragma mark 设置TableView上面显示的内容 使用此方法时候需要注意,一定要使用重用机制,否则会出现文字或图像重叠的现象
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
#pragma mark - 重写----设置有多少个分组
- (NSInteger)numberOfSectionsInTableV
#pragma mark - 重写----设置每个分组上面有多少单元格
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
#pragma mark - 重写---修改行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark - 重写----设置单元格分组的标题和标注的高度
#pragma mark 设置分组上面的标题的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection
#pragma mark 设置分组下面的标注的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection
#pragma mark - 重写----设置单元格分组的标题
//
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
// 也可以直接设置为字符串
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
#pragma mark - 重写----设置分组下面显示的视图
// 设置为UIView类型
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
// 也可以直接设置为字符串类型
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
#pragma mark - 重写----设置当我们点击Edit按钮,让TableView进入编辑状态时候左面显示出得按钮是加号、减号、还是空白
- (UITableViewCellEditingSt
// 主要由如下三种情况
// UITableViewCellEditingSt
// UITableViewCellEditingSt
// UITableViewCellEditingSt
#pragma mark - 重写----当TableView将要显示的时候进行设置 可以设置TableView隔行换背景色
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
#pragma mark - 重写----设置可以编辑 返回值为YES
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath
{
}
#pragma mark - 重写----设置可以排序移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath {
}
#pragma mark - 重写----排序移动时的方法
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
#pragma mark - 重写----判断是那个编辑的状态,然后依据状态去编辑
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingSt
#pragma mark - 重写---点击了每个单元格(Cell)触发的事件,如果可以移动的话就必须使用标题来判断
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath;
// 以上为经常使用的几个方法,下面贴上添加内容,移动,添加,删除的主要代码:
// 添加内容的主要代码:
#pragma mark 设置TableView上面显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
}
// 移动排序的主要代码:
#pragma mark - 重写----设置可以编辑 返回值为YES
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
}
#pragma mark - 重写----设置可以排序移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
}
#pragma mark - 重写----排序移动时的方法
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
}
// 添加新的单元格(cell)的主要代码
// 首先需要在头文件中声明一个cellCount和UITableViewCell以供使用
#import
@interface InsertTableViewControlle
@property (nonatomic, assign) NSUInteger cellCount;
@property (nonatomic, retain) UITableViewCell *nullTableViewCell;
@property (nonatomic, retain) NSMutableArray *tableViewDataSource;
@end
// 实现文件中进行主要操作
#pragma mark - 重写----设置编辑状态下显示的按钮是加号、减号、空
- (UITableViewCellEditingSt
}
#pragma mark - 重写----依据编辑状态进行相应的操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingSt
{
}
// 删除单元格的主要代码:
#pragma mark - 重写----设置编辑状态下显示的按钮的样式
- (UITableViewCellEditingSt
{
}
#pragma mark - 重写----判断是哪个编辑状态,进行相应的操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingSt
{
}
// 还有就是UINavigationController右上角的Edit按钮,如果你写的类继承自UITableViewController类,则直接在viewDidLoad方法中写上
// 在NavigationController上面显示出编辑按钮
#pragma mark - 设置NavigationBar右上角的按钮的不同状态显示的不同的文字和是否处于编辑的状态
- (void)toggleEdit:(UIBarButtonItem *)sender
{
}
// 我们在初始化UITableView的时候,一定要把delegate和dataSource代理设置为本身,否则是不起作用的
_myTableView.dataSource = self; // 设置数据代理为本身
_myTableView.delegate = self; // 设置样式代理为本身