我添加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) 我在存储库上使用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) 假设我有一个声明和初始化两个局部变量的函数 - 默认情况下它具有存储持续时间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
具有 …
我正在将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) 我正在开发一个我想要的应用程序:
在播放音频时尊重铃声/静音开关,和
当铃声/静音开关设置为静音时,显示一个图标,表示声音已静音.
要求1很简单:我使用的AVAudioSessionSoloAmbient
是我的应用程序的音频会话类别,因此当响铃/静音开关关闭时,我的音频会话将自动静音.
要求2似乎相当困难,因为我需要某种回调,通知或KVO,这将允许我监控交换机的位置,但Apple明确表示它不愿意提供正式公开的方式来做到这一点.也就是说,如果我能找到一种非侵入性的方式来监控交换机的位置,即使是技术上被禁止的方式(例如内部NSNotification
),我也愿意由Apple运行它.
此外,我宁愿不实施我在别处找到的一些民意调查解决方案.有关示例,请参阅"相关问题"部分.
至少在iOS版本4和5中,有一个技巧可以通过观察当前音频会话的路由属性来获取交换机的位置.除了被AVAudioSession
班级弃用之外,我还可以确认这个技巧不再是一个选择.当切换振铃/静音开关时,当前路由(包括已弃用的Audio Session
API和当前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)
但是,这有两个问题:
BOOL
指向的值arg1
似乎都没有变化.
我怀疑某个对象GSEventRef
在更改静音开关时会发送一些其他对象,因为我在事件类型的声明中看到以下内容:
kGSEventRingerOff = 1012,
kGSEventRingerOn = 1013,
Run Code Online (Sandbox Code Playgroud)
但是,我很确定我无法拦截这些消息,即使我可以,这也不仅仅是"一点点"的干扰.
简单地说:Instagram应用程序基本上表现出这种行为.观看视频时,它会考虑铃声/静音开关的设置,但在开关关闭时会显示一个图标.图标消失并在移动开关后立即重新出现,我认为它必须是基于事件的,而不是轮询.
这个问题(更多)更新,询问iOS 7.但是,因为我愿意接受私有API规则的最小侵入性破坏,我认为这是一个与我自己不同的问题.
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;
根据编译器对此属性的支持,有条件地定义此宏.如果编译器不支持该属性,则宏将扩展为空.
我有一个脚本,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) 我设置:
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)
它只显示蓝色而不是灰色.任何的想法?谢谢.
我的一个朋友在处理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
,不应做任何事情.在二进制中,这与所有1
s进行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
,或者出于其他原因,你可以在这里找到它.
另外,我的第一个野生的猜测是,有一些偷偷摸摸的事情发生时,我们投ilen
自size_t
到uint32_t
,但我仍然停留和困惑.
我目前正在阅读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)
这意味着必须将CALayer
s支持UIView
的隐式和显式动画放在动画块中.
但是,我发现这显然是不真实的.具体来说,我已经使用UIView
动画块之外的Core Animation类成功实现了显式动画.
我误解了这段话,或者它已经过时了,还是别的什么?
一些额外的说明:
我假设"UIView类默认禁用图层动画,但在动画块内重新启用它们"是指该+[UIView setAnimationsEnabled:]
方法.当我回到那个可以做这样一台电脑,我会检查,看看是否+[UIView areAnimationsEnabled]
回报YES
或NO
.