我正在尝试创建一个新文件,但事情似乎并没有像我期望的那样工作.这是我尝试过的:
File.new "out.txt"
File.open "out.txt"
File.new "out.txt","w"
File.open "out.txt","w"
Run Code Online (Sandbox Code Playgroud)
根据我在网上阅读的所有内容,所有这些都应该有效但是每一个都给我这个:
ERRNO::ENOENT: No such file or directory - out.txt
Run Code Online (Sandbox Code Playgroud)
这发生在IRB以及ruby文件中.我错过了什么?
我有一个自定义按钮样式如下:
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" >
<shape>
<gradient
android:startColor="@color/Shadow"
android:endColor="@color/Highlight"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#000" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="@color/Shadow"
android:endColor="@color/Highlight"
android:angle="270" />
<stroke
android:width="1dp"
android:color="#000" />
<corners
android:radius="3dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="@color/Shadow"
android:endColor="@color/Highlight"
android:angle="90" />
<stroke
android:width="1dp"
android:color="#000" />
<corners
android:radius="50dp" />
<padding
android:top="10dp"
android:bottom="10dp" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
我现在想要创建一个看起来像这样的按钮,除了右角没有圆角.我知道如何单独设置角半径,但有没有办法继承自定义按钮的所有其他属性?
我试过了:
<?xml version="1.0" …Run Code Online (Sandbox Code Playgroud) 我有一个视图设置有两个UICollectionViews.这些视图中的每一个都有一个支持不同大小的数组.collection1由array1支持,collection2由array2支持.问题是,从numberOfItemsInSection为collection1返回的任何数字都应用于两个集合视图.
例如,如果array1的大小为4,array2的大小为5,则两个集合都将显示4个元素.如果array1的大小为5而array2的大小为4,那么当我一直滚动collection2时,它会调用cellForItemAtIndexPath,itemIndex为5,这样我就得到了一个NSRangeException.
如何让每个collectionView使用它自己的大小?
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
if(view == self.colleciton1){
return self.array1.count;
} else if (view == self.collection2){
return self.array2.count;
}
return 0;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
if(cv == self.collection1){
CharacterCell *cell = [cv dequeueReusableCellWithReuseIdentifier:FIRST_CELL_IDENTIFIER forIndexPath:indexPath];
cell.label.text = self.array1[indexPath.item];
return cell;
} else if (cv == self.collection2){
EpisodeCell *cell = [cv dequeueReusableCellWithReuseIdentifier:SECOND_CELL_IDENTIFIER forIndexPath:indexPath];
cell.label.text = self.array2[indexPath.item];
return cell;
}
return nil;
}
Run Code Online (Sandbox Code Playgroud)
我已经包含了一个git repo,其中包含一个说明问题的项目.
git@github.com:civatrix/MultipleCollectionViews.git
我正在继承UICollectionViewCell并使用自动布局在代码中进行所有布局.这是我的init方法:
- (id)initWithFrame:(CGRect)frame{
frame = CGRectMake(0, 0, 403, 533);
if (self = [super initWithFrame:frame]) {
self.translatesAutoresizingMaskIntoConstraints = NO;
PBCardPricesViewController *pricesView = [[PBCardPricesViewController alloc] init];
[self addSubview:pricesView.view];
UIImageView *background = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CardBackground"]];
[self addSubview:background];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-(20)-[background]|" options:0 metrics:nil views:@{@"background":background}]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:pricesView.view attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:background attribute:NSLayoutAttributeLeft multiplier:1 constant:0]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[background]|" options:0 metrics:nil views:@{@"background":background}]];
[self addConstraint:[NSLayoutConstraint constraintWithItem:pricesView.view attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:background attribute:NSLayoutAttributeTop multiplier:1 constant:0]];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
当我注释掉translateAutoresizingMask行时,我得到:
Unable to simultaneously satisfy constraints.
Probably at least one of …Run Code Online (Sandbox Code Playgroud)