小编rav*_*ron的帖子

UICollectionView:必须使用非零布局参数进行初始化

我添加UICollectionView了代码.
现在,应用程序崩溃并显示消息:UICollectionView must be initialized with a non-nil layout parameter.
你有什么想法来解决它吗?
CollectionCell是自定义类UICollectionViewCell.

@property (nonatomic, strong) UICollectionView* collectionView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.collectionView = [[UICollectionView alloc]init];
    [self.collectionView registerClass:[CollectionCell class] forCellWithReuseIdentifier:@"cell"];
    UICollectionViewFlowLayout* flowLayout = [[UICollectionViewFlowLayout alloc]init];
    flowLayout.itemSize = CGSizeMake(100, 100);
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [self.collectionView setCollectionViewLayout:flowLayout];

    self.collectionView.frame = CGRectMake(0, 60, 320, 500);
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.view addSubview:self.eventCollection];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview

59
推荐指数
6
解决办法
6万
查看次数

Git慢慢枚举不存在的未跟踪文件

我在存储库上使用git进行源代码控制.最近它已经开始警告我在使用时枚举未跟踪文件需要多长时间git status:

$ git status
On branch my_branch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   My_Project/my_source.c


It took 3.24 seconds to enumerate untracked files. 'status -uno'
may speed it up, but you have to be careful not to forget to add
new files yourself (see 'git help status').
no changes added to commit (use "git add" and/or "git …
Run Code Online (Sandbox Code Playgroud)

git git-status

21
推荐指数
3
解决办法
4391
查看次数

安全地将指针传递给自动变量来运行?

假设我有一个声明和初始化两个局部变量的函数 - 默认情况下它具有存储持续时间auto.然后,该函数调用第二个函数,它传递这两个局部变量的地址.第二个功能可以安全地使用这些指针吗?

一个简单的程序化示例,以补充该描述:

#include <stdio.h>

int adder(int *a, int *b)
{
    return *a + *b;
}

int main()
{
    auto int a = 5;    // `auto' is redundant; included for clarity
    auto int b = 3;

    // adder() gets the addresses of two auto variables! is this an issue?
    int result = adder(&a, &b);
    printf("5 + 3 = %d\n", result);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该程序按预期工作,打印5 + 3 = 8.

通常,当我对C有疑问时,我会转向标准,这也不例外.具体来说,我检查了ISO/IEC 9899,§6.2.4.它在那里说:

4声明标识符且没有链接且没有存储类说明符的对象static具有 …

c pointers lifetime

14
推荐指数
2
解决办法
2421
查看次数

source-map-loader在哪里适合使用Webpack进行TypeScript编译?

我正在将TypeScript添加到当前所有JavaScript Web应用程序的构建过程中,其构建过程围绕Webpack构建.我一直在关注TypeScript的从JavaScript迁移的文章,并对建议的Webpack配置¹有疑问,为方便起见,下面复制了以下内容:

module.exports = {
    entry: "./src/index.ts",
    output: {
        filename: "./dist/bundle.js",
    },

    // Enable sourcemaps for debugging webpack's output.
    devtool: "source-map",

    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },

    module: {
        loaders: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" }
        ],

        preLoaders: [
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'. …
Run Code Online (Sandbox Code Playgroud)

typescript webpack

13
推荐指数
1
解决办法
1212
查看次数

检测振铃/静音开关位置变化

我正在开发一个我想要的应用程序:

  1. 在播放音频时尊重铃声/静音开关,和

  2. 当铃声/静音开关设置为静音时,显示一个图标,表示声音已静音.

要求1很简单:我使用的AVAudioSessionSoloAmbient是我的应用程序的音频会话类别,因此当响铃/静音开关关闭时,我的音频会话将自动静音.

要求2似乎相当困难,因为我需要某种回调,通知或KVO,这将允许我监控交换机的位置,但Apple明确表示它不愿意提供正式公开的方式来做到这一点.也就是说,如果我能找到一种非侵入性的方式来监控交换机的位置,即使是技术上被禁止的方式(例如内部NSNotification),我也愿意由Apple运行它.

此外,我宁愿不实施我在别处找到的一些民意调查解决方案.有关示例,请参阅"相关问题"部分.


我学到了什么(又名什么不行)

  • 至少在iOS版本4和5中,有一个技巧可以通过观察当前音频会话的路由属性来获取交换机的位置.除了被AVAudioSession班级弃用之外,我还可以确认这个技巧不再是一个选择.当切换振铃/静音开关时,当前路由(包括已弃用的Audio SessionAPI和当前AVAudioSession类的C函数报告)都不会更改.

  • AVSystemController是一个似乎有很多承诺的内部类.调用确实- (BOOL)toggleActiveCategoryMuted会使sharedAVSystemController我的应用程序的音频静音.此外,共享单例AVSystemController_SystemVolumeDidChangeNotification在通过音量按钮更改系统音量时发布通知.不幸的是,这个通知不是为响应环/静音开关的变化而发布的(尽管这个可疑的来源说它应该).

  • 据我所知,有没有 NSNotification š张贴由任何对象响应于环/无声开关位置的变化.在将自己添加为默认中心中所有通知的观察者后,我得出了这个结论:

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:nil object:nil];
    
    Run Code Online (Sandbox Code Playgroud)

    然后切换响铃/静音开关.没有.

  • AVSystemController课程有一个很有前途的签名方法:

    - (BOOL)getActiveCategoryMuted:(BOOL*)arg1;
    
    Run Code Online (Sandbox Code Playgroud)

    但是,这有两个问题:

    1. 响应于切换振铃/静音开关,返回值和BOOL指向的值arg1似乎都没有变化.
    2. 由于方法签名,这种方法(据我所知)并不是KVO的候选者.

  • 我怀疑某个对象GSEventRef在更改静音开关时会发送一些其他对象,因为我在事件类型的声明中看到以下内容:

    kGSEventRingerOff = 1012,
    kGSEventRingerOn = 1013,
    
    Run Code Online (Sandbox Code Playgroud)

    但是,我很确定我无法拦截这些消息,即使我可以,这也不仅仅是"一点点"的干扰.


为什么我相信这是可能的

简单地说:Instagram应用程序基本上表现出这种行为.观看视频时,它会考虑铃声/静音开关的设置,但在开关关闭时会显示一个图标.图标消失并在移动开关后立即重新出现,我认为它必须是基于事件的,而不是轮询.


相关问题

iphone audio avaudioplayer ios ios7.1

12
推荐指数
0
解决办法
3617
查看次数

为什么UIKit方法不使用NS_REQUIRES_SUPER?

UIKit可以对很多类进行子类化,但是文档要求某些方法(如果被覆盖)必须确保仍然可以调用super.例如:

-[UIViewController viewWillAppear:]
-[UITableViewCell didTransitionToState:]
<every method UIPercentDrivenInteractiveTransition declares>
Run Code Online (Sandbox Code Playgroud)

为什么Apple选择不附加NS_REQUIRES_SUPER这些方法的声明,因为它们确实"需要超级"?我的第一个想法是向后兼容早期版本的clang,但在阅读以下clang文档摘录后,我认为即使这不是问题:

请注意,在OS X和iOS上,Foundation框架提供了一个方便的宏NS_REQUIRES_SUPER,为此属性提供语法糖:

- (void)foo NS_REQUIRES_SUPER;

根据编译器对此属性的支持,有条件地定义此宏.如果编译器不支持该属性,则宏将扩展为空.

objective-c clang ios

12
推荐指数
1
解决办法
1023
查看次数

在git status之后git diff-files输出更改

我有一个脚本,update.py它下载我的git存储库中跟踪的新版本文件:

$ python update.py
Doing work...
Done
$ git status
On branch my-branch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   foo.txt
    modified:   bar.txt
    modified:   baz.txt

no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)

有时,下载的文件与已有的文件相同HEAD,因此下载后工作目录是干净的:

$ python update.py
Doing work...
Done
$ git status
On branch my-branch
nothing to commit, working directory clean …
Run Code Online (Sandbox Code Playgroud)

git git-diff

10
推荐指数
1
解决办法
643
查看次数

无法更改UITableView蓝色高亮颜色

我设置:

cell.selectionStyle = UITableViewCellSelectionStyleGray;
Run Code Online (Sandbox Code Playgroud)

并使用代码突出显示一行:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection: 0];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone
Run Code Online (Sandbox Code Playgroud)

即使我设置为灰色,高光颜色始终为蓝色.如果我设置:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
Run Code Online (Sandbox Code Playgroud)

它工作正常,没有突出显示.但是不能合作:

cell.selectionStyle = UITableViewCellSelectionStyleGray;
Run Code Online (Sandbox Code Playgroud)

它只显示蓝色而不是灰色.任何的想法?谢谢.

objective-c ios

9
推荐指数
3
解决办法
1万
查看次数

为什么AND和uint32值为0xFFFFFFFF?

我的一个朋友在处理SHA加密的函数中查看了这个开源SSL代码,并注意到这个奇怪的片段:

ctx->total[0] += (uint32_t) ilen;         // ilen is of type size_t
ctx->total[0] &= 0xFFFFFFFF;              

if( ctx->total[0] < (uint32_t) ilen )
    ctx->total[1]++;
Run Code Online (Sandbox Code Playgroud)

我们无法弄清楚这个代码的两个方面.首先,ANDs ctx->total[0](类型uint32_t)与0xFFFFFFFF,不应做任何事情.在二进制中,这与所有1s进行AND运算,它应该产生相同的值.在我看来,这两行是相同的:

ctx->total[0] &= 0xFFFFFFFF;
ctx->total[0] =  ctx->total[0];
Run Code Online (Sandbox Code Playgroud)

如果我是对的,为什么这条线呢?一些安全原因?如果我错了,怎么和为什么?

其次,if假设AND没有做任何事情,我们不明白什么时候会成真.如果AND什么都不做,那么if基本上是:

if (ctx->total[0] < ctx->total[0])
Run Code Online (Sandbox Code Playgroud)

这永远不应该是真的.我们缺少什么?


如果你想看到头文件来说服自己ctx->total[0]是类型uint32_t,或者出于其他原因,你可以在这里找到它.

另外,我的第一个野生的猜测是,有一些偷偷摸摸的事情发生时,我们投ilensize_tuint32_t,但我仍然停留和困惑.

c bit-manipulation

6
推荐指数
1
解决办法
2091
查看次数

为什么文档表明CALayer动画必须在UIView动画块中?

我目前正在阅读Apple的核心动画指南,在那里我发现以下关于iOS中的图层支持视图的段落:

如果要使用Core Animation类来启动动画,则必须从基于视图的动画块中发出所有Core Animation调用.UIView类默认禁用图层动画,但在动画块内重新启用它们.因此,您在动画块之外所做的任何更改都不会生成动画.

在引号下方,文档包含以下代码清单:

[UIView animateWithDuration:1.0 animations:^{
   // Change the opacity implicitly.
   myView.layer.opacity = 0.0;

   // Change the position explicitly.
   CABasicAnimation* theAnim = [CABasicAnimation animationWithKeyPath:@"position"];
   theAnim.fromValue = [NSValue valueWithCGPoint:myView.layer.position];
   theAnim.toValue = [NSValue valueWithCGPoint:myNewPosition];
   theAnim.duration = 3.0;
   [myView.layer addAnimation:theAnim forKey:@"AnimateFrame"];
}];
Run Code Online (Sandbox Code Playgroud)

这意味着必须将CALayers支持UIView的隐式和显式动画放在动画块中.

但是,我发现这显然是不真实的.具体来说,我已经使用UIView动画块之外的Core Animation类成功实现了显式动画.

我误解了这段话,或者它已经过时了,还是别的什么?


一些额外的说明:

我假设"UIView类默认禁用图层动画,但在动画块内重新启用它们"是指该+[UIView setAnimationsEnabled:]方法.当我回到那个可以做这样一台电脑,我会检查,看看是否+[UIView areAnimationsEnabled]回报YESNO.

core-animation calayer uiview ios

6
推荐指数
1
解决办法
1057
查看次数