first of all I want to thank all of you! :)
So, I have a Main view Controller with Table View, with custom cells from another class. I have made custom selection of the cell (you have to slide the cell of the view). In that action I'm calling method in the main View Controller to send SMS. But I'm getting this warning, and the SMS controller is not appearing. I know, that this error message means, that it can't open SMS Controller, because the main Controller is not loaded? I tried some codes from here, but nothing works for me. My classes currently look like this:
Main controller.m
.
.
.
-(void)viewWillAppear:(BOOL)animated
{
[self.citiesButton setTitle:rowValue forState:UIControlStateNormal];
UITableView *tableView = (id)[self.view viewWithTag:1];
{
tableView.rowHeight = 100;
UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:CellTableIdentifier];
UIEdgeInsets contentInset = tableView.contentInset;
contentInset.top = 20;
[tableView setContentInset:contentInset];
NSLog(@"rowValue is %@", rowValue);
self.city = [_dict objectForKey:rowValue];
}
NSLog(@"View will appear");
[tableView reloadData];
}
-(void)sendSMS
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Testy Test";
controller.recipients = [NSArray arrayWithObjects:@"774252704", nil];
controller.messageComposeDelegate = self;
[self dismissViewControllerAnimated:YES completion:^{
[self presentViewController:controller animated:YES completion:nil];
}];
}
}
So I'm trying to close the main controller first and then display the smsController, but still no luck. I think, that the problem will be in that I'm calling the method from the TableViewCell class, but still, the table is created after the view is loaded, so I'm really lost here.
Thank you very much for your time!
=====EDIT=====
Here is the custom cell class, from where I call the sendSMS method
tableViewCell.m
#import "TableViewCell.h"
#import "TableViewController.h"
static NSString *CellTableIdentifier = @"TableViewCell";
@implementation TableViewCell
@synthesize timeLabel = _timeLabel;
@synthesize priceLabel = _priceLabel;
@synthesize infoLabel = _infoLabel;
- (void)awakeFromNib
{
// Initialization code
}
-(void)layoutSubviews
{
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognizer:)];
[self addGestureRecognizer:panGesture];
}
-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:CellTableIdentifier];
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
-(void)panGestureRecognizer:(UIPanGestureRecognizer *)sender{
CGPoint translation = [sender translationInView:self];
TableViewController *mainController = [[TableViewController alloc] init];
//NSLog(@"Panned with translation point: %@", NSStringFromCGPoint(translation));
sender.view.center = CGPointMake(sender.view.center.x + translation.x,
sender.view.center.y);
CGPoint breakingPoint = CGPointMake(320,sender.view.center.y);
CGPoint startPoint = CGPointMake(150, sender.view.center.y);
CGPoint endPoint = CGPointMake(500, sender.view.center.y);
if (sender.view.center.x <= startPoint.x) {
sender.view.center = startPoint;
}
if (sender.state == UIGestureRecognizerStateEnded) {
if (sender.view.center.x >= breakingPoint.x) {
[UIView animateWithDuration:0.2
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
sender.view.center = endPoint;
}
completion:^(BOOL finished){
NSLog(@"Bought!");
[mainController sendSMS];
}];
} else {
//recognizer.view.center = startPoint;
[UIView animateWithDuration:0.2
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
sender.view.center = startPoint;
}
completion:^(BOOL finished){
NSLog(@"Returned!");
}];
}
}
[sender setTranslation: CGPointZero inView: self];
}