只有我第二次使用UICollectionView,也许我已经咬过的东西超过了我可以咀嚼但是:
我正在实现一个UICollectionView(myCollectionView),它使用我已经子类化的自定义UICollectionViewCell.子类化单元格(FullReceiptCell)包含UITableView,并且是viewcontroller的大小.我试图允许FullReceiptCells之间的水平滚动.
包含myCollectionView的子类UICollectionViewController正被推送到导航控制器堆栈.目前,myCollectionView loas和水平滚动已启用.但是,没有细胞可见.我已经证实了这一点
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
已运行并返回一个大于0的整数.我还确认myCollectionView的委托和数据源在IB中正确设置为子类UICollectionViewController.
要加载单元格的方法:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
没有被召唤.
这是我在该控制器中推送UICollectionViewController和viewDidLoad方法的地方(注意:initWithBill是普通初始化程序的覆盖):
在之前的ViewControllers .m文件中:
FullReceiptViewController *test = [[FullReceiptViewController alloc] initWithBill:currentBill];
test.title = @"Review";
[self.navigationController pushViewController:test animated:YES];
Run Code Online (Sandbox Code Playgroud)
在FullReceiptViewController.m中:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[self.myCollectionView registerClass:[FullReceiptCell class] forCellWithReuseIdentifier:@"FullReceiptCellIdentifier"];
self.myCollectionView.pagingEnabled = YES;
// Setup flowlayout
self.myCollectionViewFlowLayout = [[UICollectionViewFlowLayout alloc] init];
[self.myCollectionViewFlowLayout setItemSize:CGSizeMake(320, 548)];
[self.myCollectionViewFlowLayout setSectionInset:UIEdgeInsetsMake(0, 0, 0, 0)];
[self.myCollectionViewFlowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
self.myCollectionViewFlowLayout.minimumLineSpacing = 0;
self.myCollectionViewFlowLayout.minimumInteritemSpacing = …
Run Code Online (Sandbox Code Playgroud) 我有一个UICollectionView,它由一个自定义的UICollectionViewCell子类组成.单元格正确显示,并通过触发此方法正确响应用户的触摸:
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
但是,我理解当用户触摸单元格时,它应该突出显示(蓝色),然后当用户抬起手指时高光应该消失.这不会发生.有什么想法吗?
这是一些相关的代码:
在UICollectionView的数据源中:
@implementation SplitCheckViewCollection
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = @"ReceiptCellIdentifier";
SplitCheckCollectionCell *cell = (SplitCheckCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
cell.cellName.text = [NSString stringWithFormat:@"%@%i",@"#",indexPath.row+1];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
在UICollectionViewCell的实现中:
@implementation SplitCheckCollectionCell
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"SplitCheckCollectionCell" owner:self options:nil];
if ([arrayOfViews count] < 1) {
return nil;
}
if (![[arrayOfViews objectAtIndex:0] isKindOfClass:[UICollectionViewCell class]]) {
return nil;
}
self = [arrayOfViews objectAtIndex:0];
} …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写测试和应用程序代码,以便在已尝试创建用户或访问新用户路径时重定向已登录到root_path的用户.
以下是我在user_pages_spec.rb中编写的测试:
describe "for signed in users" do
let(:user) { FactoryGirl.create(:user) }
before { sign_in user }
describe "using a 'new' action" do
before { get new_user_path }
specify { response.should redirect_to(root_path) }
end
describe "using a 'create' action" do
before { post users_path }
specify { response.should redirect_to(root_path) }
end
end
Run Code Online (Sandbox Code Playgroud)
UsersController:
class UsersController < ApplicationController
before_action :unsigned_in_user, only: [:create, :new]
def new
@user = User.new
end
def create
@user = User.new(user_params)
if @user.save
sign_in @user
flash[:success] = "Welcome …
Run Code Online (Sandbox Code Playgroud) 我是新手,请耐心等待:
我在IB中有一个包含UIScrollView的.xib,其中嵌入了UITableView.我想将自定义UITableViewCells加载到UITableView中.我在IB中创建了四个/五个自定义单元格,但无法正确加载第一个.
以下是IB的相关截图:
我已经将在IB中创建的自定义UITableViewCell的类设置为我创建的名为"itemCell"的UITableView类.此外,我已将三个文本字段出口和代理连接到"itemCell".
这是itemCell.h:
#import <UIKit/UIKit.h>
@interface itemCell : UITableViewCell
@property (weak, nonatomic) IBOutlet UITextField *quantityTextField;
@property (weak, nonatomic) IBOutlet UITextField *itemTextField;
@property (weak, nonatomic) IBOutlet UITextField *priceTextField;
@end
Run Code Online (Sandbox Code Playgroud)
这是itemCell.m:
#import "itemCell.h"
@implementation itemCell
@synthesize quantityTextField,itemTextField,priceTextField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end
Run Code Online (Sandbox Code Playgroud)
在filecontroller.m中,这是rootcontroller .xib的实现文件,我根据用户按下按钮(将其添加到数组)创建一个新单元格,然后重新加载tableview.我没有错误,但我得到的是正常的单元格,而不是我在IB中创建的单元格.这是rootcontroller.m.任何帮助表示赞赏.
- (void)viewDidLoad
{
[super …
Run Code Online (Sandbox Code Playgroud) 我以编程方式设置一个UICollectionViewCell
被调用的自定义CheckCell
,如下所示:
[self.myCollectionView cellForItemAtIndexPath:indexPath] setSelected:YES];
if ([[self.myCollectionView cellForItemAtIndexPath:indexPath] isSelected]) {
NSLog(@"Selected");
}
NSLog(@"%i",[self.myCollectionView indexPathsForSelectedItems].count);
Run Code Online (Sandbox Code Playgroud)
第一个NSLog打印"选定",让我相信单元格IndexPath
确实被选中.但是,第二个NSLog的结果为0.为什么没有将所选单元格的索引添加到indexPathsForSelectedItems
?