IOS(1)

本文介绍在iOS开发中如何使用#pragma mark标记来提高代码导航的效率,通过在代码中添加特定的注释,使得开发者能够更快速地定位到特定的功能模块或代码段落,从而提升开发体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
{
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值