I'm getting this error with my app: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<ViewController: 0x17e60c10>) has no segue with identifier 'dateTimeString''. Code is this:
ViewController.m
-(IBAction) alarmSetButtonTapped:(id)sender {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.timeZone = [NSTimeZone defaultTimeZone];
[dateFormatter setDateFormat:#"dd:MM:YYYY:ss:mm:hh"];
NSString *dateTimeString = [dateFormatter stringFromDate: dateTimePicker.date ];
NSLog( #"Alarm Set : %#", dateTimeString );
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"dd:MM:YYYY:ss:mm:hh"];
NSDate *dateTimeSeconds = [[NSDate alloc] init];
dateTimeSeconds = [dateFormatter1 dateFromString:dateTimeString];
NSTimeInterval seconds = [[NSDate date] timeIntervalSinceDate:dateTimePicker.date];
NSLog(#"seconds %.f", seconds);
NSString *path = [NSString stringWithFormat:#"%#/Alarm-Clock.m4a", [[NSBundle mainBundle] resourcePath]];
NSURL *soundUrl = [NSURL fileURLWithPath:path];
_alarmPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
[_alarmPlayer playAtTime: _alarmPlayer.deviceCurrentTime + seconds];
NSLog( #"Alarm Set button tapped : %#", dateTimeString );
[self scheduleLocalNotificationWithDate: dateTimePicker.date];
[self performSegueWithIdentifier:#"dateTimeStringSegue" sender: nil];
[self presentMessage:(#"Alarm succesfully set for %#",dateTimeString)];
}
-(IBAction)alarmCancelButtonTapped:(id)sender {
NSLog( #"Alarm Cancel button tapped");
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[self presentMessage:#"Alarm Canceled Lazy Pants!"];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
ViewController3 *tvc = segue.destinationViewController;
NSLog(#"prepareForSegue: %#", segue.identifier);
if ([[segue identifier] isEqualToString:#"dateTimeStringSegue"])
{
tvc.dateTimeString = (#"%#",_dateTimeString);
NSLog(#"Segue");
}
}
ViewController.h
#interface ViewController : UIViewController <AVAudioPlayerDelegate>
{
IBOutlet UIDatePicker *dateTimePicker;
}
#property NSInteger numberOfLoops;
#property(readonly) NSTimeInterval deviceCurrentTime;
#property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
#property (strong, nonatomic) NSString *dateTimeString;
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
-(void) presentMessage: (NSString *) message;
-(void) scheduleLocalNotificationWithDate: (NSDate *) fireDate;
-(IBAction) alarmSetButtonTapped:(id)sender;
-(IBAction) alarmCancelButtonTapped:(id)sender;
- (BOOL)playAtTime:(NSTimeInterval)time;
#end
SegueDestination.h
#import "ViewController.h"
#interface ViewController3 : UIViewController
#property(nonatomic, readonly) NSUInteger tapCount;
#property NSInteger numberOfLoops;
#property(readonly) NSTimeInterval deviceCurrentTime;
#property (strong, nonatomic) AVAudioPlayer *alarmPlayer;
#property (strong, nonatomic) NSString *dateTimeString;
#property (strong, nonatomic) IBOutlet UILabel *dateTimePicker;
- (NSTimeInterval)timeIntervalSinceDate:dateTimePicker;
- (BOOL)playAtTime:(NSTimeInterval)time;
- (IBAction)iconsBtn:(id)sender;
#end
SegueDestination.m
#import "ViewController.h"
#interface ViewController3 ()
{
AVAudioPlayer *_alarmPlayer;
}
#end
#implementation ViewController3
- (void)viewDidLoad {
[super viewDidLoad]
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"wwv5.jpg"]];
}
- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if(touch.tapCount == 3) {
NSLog(#"Twice");
}
else
NSLog(#"UGHHHHH");
}
- (IBAction)iconsBtn:(id)sender {
}
I'm trying to access the dateTimeString in my 2nd ViewController but whenever I click the button that is supposed to send it my app terminates with that error. This is the first time I've attempted to use segue and I'm not going so great with it. Once this error is sorted will I be able to call dateTimeStringin the 2nd ViewControllerand get the value set in the 1st ViewController?
Thanks!
Edit: I have already done the identifier in storyboard.
In your storyboard you need to set Identifier for your segue:
Related
Hi all i am working with FSCalandar in my project. Everything is working fine but i am not able change calendar date color for the date which will entered by user. Basically i want to add the functionality of present and absent in my project using FSCalander. i already called fscalanderappearance delegate method.Please look at my code.
This is .h file
#interface CalTableCellTableViewCell : UITableViewCell <FSCalendarDelegate, FSCalendarDataSource, FSCalendarDelegateAppearance>
{
NSDate *myDate;
NSDate *EndDate;
NSMutableArray *array;
}
#property (weak , nonatomic) FSCalendar *calendar;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *calendarHeightConstraint;
#property (weak, nonatomic) IBOutlet UIView *calview;
#property (strong, nonatomic) NSDate *selectedDate;
#property (strong, nonatomic) NSDictionary *fillSelectionColors;
#property (strong, nonatomic) NSDictionary *fillDefaultColors;
#property (strong, nonatomic) NSDictionary *borderDefaultColors;
#property (strong, nonatomic) NSDictionary *borderSelectionColors0;
#property (strong, nonatomic) NSArray *datesWithEvent;
#property (strong, nonatomic) NSArray *datesWithMultipleEvents;
#end
This is .m file.
#import "CalTableCellTableViewCell.h"
#implementation CalTableCellTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
myDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:#"myDateKey"];
NSLog(#"mydate %#", myDate);
EndDate = (NSDate *)[[NSUserDefaults standardUserDefaults] objectForKey:#"EndDateKey"];
FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 0, 250, 150)];
calendar.dataSource = self;
calendar.delegate = self;
[self.contentView addSubview:calendar];
self.calendar = calendar;
_calendar.scrollDirection = FSCalendarScrollDirectionVertical;
calendar.appearance.caseOptions = FSCalendarCaseOptionsHeaderUsesUpperCase|FSCalendarCaseOptionsWeekdayUsesSingleUpperCase;
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = #"d.M.yyyy";
NSString *string = [formatter stringFromDate:[NSDate date]];
NSLog(#"current date %#", string);
_calendar.appearance.selectionColor = [UIColor blueColor];
_calendar.appearance.todayColor = [UIColor greenColor];
_calendar.appearance.cellShape = FSCalendarCellStyleRectangle;
NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
NSArray *testarray = [userDef objectForKey:#"name"];
array = [[NSMutableArray alloc]initWithArray:testarray];
NSLog(#"arraydata %#", array);
self.datesWithEvent = #[#"2016-09-03",
#"2015-10-06",
#"2015-10-12",
#"2015-10-25"];
self.datesWithMultipleEvents = #[#"2015-10-08",
#"2015-10-16",
#"2015-10-20",
#"2015-10-28"];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)calendar:(FSCalendar *)calendar boundingRectWillChange:(CGRect)bounds animated:(BOOL)animated
{
_calendarHeightConstraint.constant = CGRectGetHeight(bounds);
[self.contentView layoutIfNeeded];
}
- (NSDate *)minimumDateForCalendar:(FSCalendar *)calendar
{
return myDate;
}
- (NSDate *)maximumDateForCalendar:(FSCalendar *)calendar
{
return EndDate;
}
#pragma mark - <FSCalendarDelegateAppearance>
- ( UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleDefaultColorForDate:(NSDate *)date;
{
NSString *datestring = [calendar stringFromDate:myDate format:#"yyyy-MM-dd"];
if ([_datesWithEvent containsObject:datestring]) {
NSLog(#"test");
return calendar.appearance.borderDefaultColor = [UIColor redColor];
}
else if ([_datesWithMultipleEvents containsObject:datestring])
{
NSLog(#"testing");
}
return nil;
}
Please help if anyone go with this problem. thanks. Delegates method not called.
You can apply FSCalendar Data, Delegate & FSCalendarDelegateAppearance to the TableViewController or to the ViewController that contains TableView instead of implementing it in UITableViewCell. Then override the method titleDefaultColorForDate as shown below. It works for me.
-(UIColor *)calendar:(FSCalendar *)calendar appearance:(FSCalendarAppearance *)appearance titleDefaultColorForDate:(NSDate *)date{
self.formatter = [[NSDateFormatter alloc] init];
self.formatter.dateFormat = #"yyyy/MM/dd";
NSString *CurrentDate = [self.formatter stringFromDate:date];
NSString *Today = [self.formatter stringFromDate:[_Calendar today]];
//_bookedDates are array of specific dates
if([_bookedDates containsObject:CurrentDate])
//if booking dates contains currentdate change the color of the title
return [UIColor whiteColor];
else
return appearance.titlePlaceholderColor;
}
Here is my button function where I pass the data.
The problem is Area and Country details are passed to the next ViewController but latitude and longitude return null.
In ViewController.m :
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [[ForecastViewController alloc] init];
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(#"%#%#",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
}
In ForecastViewController.h
//
// ForecastViewController.h
// Weather App
//
// Created by Mac-Mini-2 on 10/02/16.
// Copyright © 2016 Mac-Mini-2. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Reachability.h>
#interface ForecastViewController : UIViewController <UITableViewDataSource,UITableViewDelegate>
#property (weak, nonatomic) IBOutlet UILabel *place;
#property (weak, nonatomic) IBOutlet UITableView *table;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
#property NSString *Area;
#property NSString *Country;
#property NSString *latitude;
#property NSString *longitude;
#end
In ForecastViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.table.delegate = self;
self.table.dataSource = self;
self.place.text = [NSString stringWithFormat:#"%#, %#",self.Area,self.Country];
locationName = [NSString stringWithFormat:#"%#, %#",self.Area,self.Country];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
metric = [defaults boolForKey:#"metric"];
Reachability *reach = [Reachability reachabilityWithHostName:#"www.google.com"];
NSInteger x = [reach currentReachabilityStatus];
if (x > 0)
{
reachable = YES;
NSLog(#"%#, %#",self.latitude,self.longitude);
[self getForecast:self.latitude longitudes:self.longitude];
}
else
{
reachable = NO;
[self getData];
errorMsg = #"Because of unavailability of Network Realtime information wont be available.";
[self performSelectorOnMainThread:#selector(displayAlert) withObject:NULL waitUntilDone:YES];
}
[reach startNotifier];
}
Please let me know where I could have gone wrong here.
I checked by logging the data onto console. The area and country is printed but longitude and latitude give null values.
if you are doing a push to ForecastViewController, maybe implementing prepareForSegue:sender: is your best option.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"viewForecast"]){
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
[(ForecastViewController *) [segue destinationViewController] setArea:area];
[(ForecastViewController *) [segue destinationViewController] setCountry:country];
...
...
}
}
Could I the that latitude and longitude are stored as numbers in the first controller? Are you sure that 'sendDetails.latitude' and 'longitude' are set correctly in 'ViewController'?
I think you need to edit two point firstly in ForecastViewController.h set
#property (Strong, nonatomic) NSString *Area;
#property (Strong, nonatomic) NSString *Country;
#property (Strong, nonatomic) NSString *latitude;
#property (Strong, nonatomic) NSString *longitude;
and #synthsize it in ForecastViewController.m.
secondly:-
- (IBAction)forecast:(UIButton *)sender
{
ForecastViewController *sendDetails = [self.storyboard instantiateViewControllerWithIdentifier:#"your ForecastViewController name in storyboard"];
NSArray *seperate = [full componentsSeparatedByString:#", "];
Area = seperate[0];
Country = seperate[1];
sendDetails.Area = Area;
sendDetails.Country = Country;
NSLog(#"%#%#",self.longitude,self.latitude);
NSString *lt = self.latitude;
NSString *ln = self.longitude;
sendDetails.longitude = lt;
sendDetails.latitude = ln;
[self.navigationController pushViewController:sendDetails animated:YES];
}
I am trying to implement the module for setting the map parameters before adding the new marker.
The flow is initialing new SliderViewCOntroller from parent mapViewController. After setting the values at SliderViewController and saving their values, it passes back to the parent mapViewCOntroller with new coordinates added. For the time being, the variable for the coordinates are only the global variables on the mapViewCOntroller
Actually, after saving the parameters, it shows the EXEC_BAD)ACCESS (code=1 , address = 0xc)
The code highlights at the
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
on the SliderViewController.m
Would you please tell me are there any other alternatives to pass the data back from child viewController to parent ViewController using protocols and delegate ?
The below is my working:
MapViewController.h
#import <MessageUI/MessageUI.h>
#import <GoogleMaps/GoogleMaps.h>
#import <UIKit/UIKit.h>
#import "SliderViewController.h"
#interface MapViewController : UIViewController<GMSMapViewDelegate , SliderViewControllerDelegate>{
}
#property (nonatomic) float verticalSliderValue;
#property (nonatomic) float circleSliderValue;
#end
MapViewController.m
//initiaing
-(void) mapView:(GMSMapView *)mapView didLongPressAtCoordinate:(CLLocationCoordinate2D)coordinate{
p = coordinate;
SliderViewController * sliderVC = [self.storyboard instantiateViewControllerWithIdentifier:#"SliderViewController"];
sliderVC.view.backgroundColor = [UIColor colorWithWhite:1.0 alpha:1.0];
sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:sliderVC animated:YES completion:NULL];
[sliderVC release];
}
//receiving
- (void)passValue:(float )value1 : (float )valueCiruclar
{
NSLog(#"This was returned from ViewControllerB %ff",value1);
NSLog(#"This was returned from ViewControllerSlider %ff",valueCiruclar);
CheckPoints *myCar=[[CheckPoints alloc] init];
[myCar setState:0];
[myCar setLatitude:p.latitude];
[myCar setLongitude:p.longitude];
NSString* theTextValue = #"Desitnation";
[myCar setDesp:theTextValue];
[array addObject:myCar];
CheckPoints *lastChk = array.lastObject;
[self writeToTextFile:[NSString stringWithFormat:#"%#%#%#%#%#%#", lastChk.getDesp , #"\n",[NSString stringWithFormat:#"%f", lastChk.getLatitude],
#"\n", [NSString stringWithFormat:#"%f", lastChk.getLongitude], #"\n" ]];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setFloat:lastChk.getLatitude forKey:#"lati"];
[defaults setFloat:lastChk.getLongitude forKey:#"longi"];
[defaults setObject:lastChk.getDesp forKey:#"desp"];
[defaults synchronize];
for (int i = 0; i < [array count]; i++) {
CheckPoints *current = [array objectAtIndex:i];
if(current.getLatitude != lastChk.getLatitude && current.getLongitude != lastChk.getLongitude){
[current setState:1];
NSString* previousTitle = [NSString stringWithFormat:#"%#%#", #"Checkpoint" ,[NSString stringWithFormat:#"%i", i+1]];
[current setDesp:previousTitle];
}
}
[self addMarkers];
}
SliderViewController.h
#import <UIKit/UIKit.h>
#import "EFCircularSlider.h"
#protocol SliderViewControllerDelegate <NSObject>
- (void)passData:(float )itemVertical : (float )itemCircular ;
#end
#interface SliderViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *uiValue;
#property (strong, nonatomic) IBOutlet UISlider *uiSlider;
#property (strong, nonatomic) IBOutlet UIButton *btnReset;
#property (strong, nonatomic) IBOutlet UILabel *uiValue2;
#property (strong, nonatomic) EFCircularSlider* circularSlider;
#property (nonatomic) float verticalSliderValue;
#property (nonatomic) float circleSliderValue;
#property (nonatomic) id <SliderViewControllerDelegate> delegate;
- (IBAction)reset:(id)sender;
- (IBAction)sliderChange:(id)sender;
- (void)buttonClicked: (id)sender;
#end
SliderViewController.m
- (IBAction)reset:(id)sender {
[self writeToTextFile:valueV :valueC];
self.uiValue.text =[NSString stringWithFormat:#"%.2f" , 0.00];
[self.uiSlider setValue:0.00];
self.uiValue2.text =[NSString stringWithFormat:#"%.2f" , 0.00];
[_circularSlider setCurrentValue:0.0f];
MapViewController * sliderVC = [self.storyboard instantiateViewControllerWithIdentifier:#"MapViewController"];
[self.delegate passData:_uiSlider.value :_circularSlider.currentValue ];
sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
[[self presentingViewController] dismissViewControllerAnimated:NO completion:nil];
}
I have a UIDatepicker and it crashes randomly in iOS7. At the simulator, the UIDatepicker works perfectly but on the real device always crash. The error is EXC_BAD_ADRESS but the Xcode doesn't give me more information.
Please help me!
My code is:
VistaRuedaViewController.h
#interface VistaRuedaViewController : UIViewController <UITableViewDataSource, UITableViewDelegate,UITabBarControllerDelegate, UITabBarDelegate>
{
NSString *fecha;
Utilidades *util;
BOOL conexion;
UIDatePicker *datePicker;
}
#property (nonatomic, retain) IBOutlet UIButton *button;
#property (nonatomic, retain) IBOutlet UITableView *table;
#property (nonatomic, strong) IBOutlet UIDatePicker *datePicker;
#property (nonatomic, retain) IBOutlet UILabel *labelAviso;
#property (nonatomic, retain) IBOutlet UITabBar *tabbar;
-(IBAction)SelectSend:(id)sender;
#end
VistaRuedaViewController.m
- (void)viewDidLoad
{
...
datePicker = [[UIDatePicker alloc]init];
[datePicker setDate:[NSDate date]];
self.datePicker.minimumDate = [NSDate date];
datePicker.datePickerMode = UIDatePickerModeDate;
...
}
-(IBAction)SelectSend:(id)sender{
UIDatePicker *dp = (UIDatePicker *) sender;
//[table reloadData];
NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
[formatter setLocale:[NSLocale currentLocale]];
[formatter setDateFormat:#"dd/MM/yyyy"];
fecha =[formatter stringFromDate:dp.date];
NSLog(#"FECHA DATAPICKER: %#", dp.date);
NSString *idioma;
NSString *currentL = [Global sharedMySingleton].test;
if([currentL isEqualToString:#"ca-ES"]){
idioma = #"ca";
}
else
{
idioma = currentL;
}
button.enabled = NO;
NSString *PlaningURLString = [NSString stringWithFormat:#"%#%#/PlaningHorario", NSLocalizedString(#"protocolo", #""), NSLocalizedString(#"servidor", #"")];
util = [[Utilidades alloc]init];
conexion = [util testInternetConnection];
if (conexion) {
Planing_pasarela *cargaPlaning = [[Planing_pasarela alloc] init];
[cargaPlaning NSURLConnectionFunction:PlaningURLString:fecha:fecha:idioma];
int ret =[cargaPlaning comprobarFlag];
button.enabled = YES;
if (ret==1) {
[table reloadData];
NSLog(#"DATAPICKER: %#", fecha);
}else{
// Usuario y token incorrectos
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:AMLocalizedString(#"logoutAlert", #"") message:AMLocalizedString(#"logout", #"") delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
alert.tag = 1;
[alert show];
}
}
}
Thank you for advance.
#property (nonatomic, strong) IBOutlet UIDatePicker *datePicker;
Why it's strong when other oultest is retain. You are using ARC or what?
If you use ARC, than all oultets shold be strong, if not then retain.
And if you use outlet, you don't need allocate it: datePicker = [[UIDatePicker alloc]init];
Use everywhere seld.datePicker instead datePicker.
You don't need UIDatePicker *datePicker; inside #interface VistaRuedaViewController ...{ }
If App is non-ARC, then you need release formatter and util
I'm changing my app so it could parse my JSON through AFNetworking and I'm getting an error when I try to change my date string with dateFormatter. I have a NSObject called "UpcomingRelease", a CollectionViewController called "UpcomingReleasesViewController" and a destinationViewController called "ReleaseViewController"
This my old code:
* UpcomingRelease.h
#interface UpcomingRelease : NSObject
#property (nonatomic, strong) NSString *release_date;
- (NSString *) formattedDate;
#end
* UpcomingRelease.m
- (NSString *) formattedDate {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:#"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSDate *newDate = [dateFormatter dateFromString:self.release_date];
[dateFormatter setDateFormat:#"MMMM dd"];
return [dateFormatter stringFromDate:newDate];
}
* ReleaseViewController.h (destinationViewController)
#import "UpcomingRelease.h"
#property (strong, nonatomic) NSDictionary *singleRelease;
#property (weak, nonatomic) IBOutlet UILabel *release_date;
* ReleaseViewController.m
#synthesize singleRelease = _singleRelease;
#synthesize release_date = _release_date;
- (void)viewDidLoad
{
[super viewDidLoad];
if([_singleRelease objectForKey:#"release_date"] != NULL)
{
self.release_date.text = [NSString stringWithFormat:#"%#", _singleRelease.formattedDate];
}
else
{
self.release_date.text = [NSString stringWithFormat:#"Releasing Soon"];
}
}
I get an error saying "Property 'formattedDate' not found on object of type 'NSDictionary').
The error already says that NSDictionary doesn't have a property called formattedDate. And right now you are calling _singleRelease.formattedDate and _singleRelease is a NSDictionary.
Change your code to the following:
if([_singleRelease objectForKey:#"release_date"] != NULL)
{
NSString *rd = [_singleRelease objectForKey:#"release_date"]; // I assume that this is a string
UpcomingRelease *upcoming = [[UpcomingRelease alloc] init];
upcoming.release_date = rd;
self.release_date.text = [NSString stringWithFormat:#"%#", upcoming.formattedDate];
}