我正在尝试使用UICollectionView,它是viewCell。我没事。但是在viewcell表单上,我有一个按钮,我打算进入设置视图。我正试图“把它推到堆栈上”。 Xcode抱怨“选择器没有可见的界面”。下面是一些代码和错误消息。
// TryColViewCell.h
#import <UIKit/UIKit.h>
#import "TryColViewContViewController.h"
@interface TryColViewCell : UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *outletNameLBL;
@property (weak, nonatomic) IBOutlet UILabel *outletCellLabel;
@property (readwrite) NSInteger intTest;
@property (readwrite) TryColViewContViewController *theHost;
- (IBAction)actionPlus1:(id)sender;
- (IBAction)actionMinus1:(id)sender;
- (IBAction)actionNameEdit:(id)sender;
// TryColViewCell.m
#import "TryColViewCell.h"
#import "SettingsViewController.h"
@implementation TryColViewCell {
@public int intCellNumber; //TODO: get this to track the row/cell #
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
- (IBAction)actionPlus1:(id)sender {
}
- (IBAction)actionMinus1:(id)sender {
}
- (IBAction)actionNameEdit:(id)sender {
NSLog(@"Name Edit");
SettingsViewController *viewControllerB =
[[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
viewControllerB.propName = _outletNameLBL.text;
[self pushViewController:viewControllerB animated:YES];
[self.theHost pushViewController:viewControllerB animated:YES];
}
@end
// PushVIewController行上的错误消息
TryColViewCell.m:83:11: No visible @interface for 'TryColViewCell'
declares the selector 'pushViewController:animated:'
答案 0 :(得分:1)
从包含集合视图的视图控制器推送新视图控制器,而不是单元格。只有UIViewController
的子类才能覆盖方法pushViewController:animated.
。
在表视图控制器中,假设您使用的是故事板,请执行以下操作:
-(UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString* identifier = @"Cell";
CellSubClass *cell =
(CellSubClass*) [tableView dequeueReusableCellWithIdentifier:identifier];
[cell.upButton addTarget:self selector:@selector(actionPlus1:)
forControlEvent:UIControlEventTouchUpInside];
[cell.downButton addTarget:self selector:@selector(actionMinus1:)
forControlEvent:UIControlEventTouchUpInside];
...
}