IOS 学习笔记(1)
#pragma mark 的用法
用于:主要是用于方便代码的查找和导航。
举例:若有如下代码
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arrayData=[NSArray arrayWithObjects:@"1",@"2",@"3",nil];
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrayData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{......}点击代码导航查询
但若在代码中加入#pragma mark标示,如下
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arrayData=[NSArray arrayWithObjects:@"1",@"2",@"3",nil];
}
#pragma mark 表格1
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrayData.count;
}
#pragma mark 表格2
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
}则再次点击快速查询得到的结果如下,可见加入了标示可以更快的方便自己查询代码
修改上面代码,若在#pragma mark 和标示(表格1、表格2)之间加入 "-",则显示的结果会更加清晰,它会主动在查询的结果中间加入分割线
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arrayData=[NSArray arrayWithObjects:@"1",@"2",@"3",nil];
}
#pragma mark - 表格1
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrayData.count;
}
#pragma mark - 表格2
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{}
本文介绍在iOS开发中如何使用#pragma mark标记来提高代码导航的效率,通过在代码中添加特定的注释,使得开发者能够更快速地定位到特定的功能模块或代码段落,从而提升开发体验。

被折叠的 条评论
为什么被折叠?



