iOS基础

关于Xcode的代码块

2018-05-03  本文已影响11人  阿洋12138

关于Xcode的代码块,我感觉应该是这个编译器里最好用的部分的,用的好的话对你开发的速度是成十倍百倍的效率提升。期间也转用过AppCode,最终还是用回Xcode,转回来又两个主要原因,首先还是被流畅度给打败了,其次虽然我也觉得idea他们公司编译器的快捷键也很强大确实也很好用,但是我还是喜欢这个代码块,对我个人来说简直就是神器。

很早之前也研究过AppCode有没有这样可以高度自定义的代码块功能,但是没有研究出来,如果有知道的大神请在评论区教一教我😂。。。

  将近3年的Xcode的使用经验,我自己多少也总结了不少自己常用的代码块,请将目光向下移动。

#pragma -mark- tableView delegate  datasuoce
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return <#count#>;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return <#cell#>;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return <#count#>;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
flowLayout.headerReferenceSize = CGSizeMake(<#width#>, <#height#>);
flowLayout.footerReferenceSize = CGSizeMake(<#width#>, <#height#>);

UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:flowLayout];
collectionView.delegate = self;
collectionView.dataSource = self;
collectionView.backgroundColor = [UIColor whiteColor];

[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forCellWithReuseIdentifier:@"cell"];
[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"head"];
[collectionView registerNib:[UINib nibWithNibName:@"" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"];
[self.view addSubview:collectionView];

self.flowLayout = flowLayout;
self.collectionview = collectionView;

[collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(self.navigationView.mas_bottom);
    make.left.bottom.right.equalTo(self.view);
}];
    - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
    {
        return <#count#>;
    }

    - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
    {
        return <#count#>;
    }

    - (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        return nil;
    }

    - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath;
    {
        //如果是头视图
        if ([kind isEqualToString:UICollectionElementKindSectionHeader])
        {

            return nil;
        }
        else if ([kind isEqualToString:UICollectionElementKindSectionFooter])
        {
            return nil;
        }

        return nil;
    }


    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath;
    {

    }

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    {
        return CGSizeMake(<#width#>, <#height#>);
    }


    - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
    {
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }


    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
    {
        return 0;
    }


    - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
    {
        return 0;
    }

上一篇 下一篇

猜你喜欢

热点阅读