I'm trying to use a UICollectionView and it's viewCell. I have that going fine. But on the viewcell form I have a button that I intend to have go to a settings view. I'm trying to "push it onto the stack". Xcode complains of "no visible interface for the selector". Some code and the error message are below.
// 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
// Error message on PushVIewController line
TryColViewCell.m:83:11: No visible @interface for 'TryColViewCell'
declares the selector 'pushViewController:animated:'
Push the new view controller from the view controller that contains the collection view, not the cell. Only a subclass of UIViewController
has the method pushViewController:animated.
to override.
In your table view controller, do something like this, assuming you are using storyboard:
-(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];
...
}