Note that there are some explanatory texts on larger screens.

plurals
  1. PONSDate is crashing my app and I have no idea why
    primarykey
    data
    text
    <p>The basics are are follows:</p> <p>I need to control 2 times (NSDate) with 1 UIDatePicker. I created a new Single View project in XCode (v 4.4.1) just to start fiddling with the items I'll be needing. I used a storyboard in the creation of the project, easy peasy. In the storyboard I got rid of the view controller and dragged out a navigation controller. Removed the table view that was the root view controller and added a regular view controller as the root view controller. On there I place a button. I dragged out another view controller and connect that button on the root view controller to this new view controller using 'Push'. Very simple. I test it, it works, basic.</p> <p>I create a class for the new view controller I just added and set the view controller in storyboard to be of that type. In storyboard I then add a UIDatePicker, a UIButton, and a UITableView (please keep in mind this is just me fiddling trying to make things work and trying to learn how to use everything, still quite new to this).</p> <p>The code for my ViewController class is as follows:</p> <p><strong>NewViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface Reminders : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt; { NSInteger selectedRow; } @property (nonatomic, retain) NSDate *amTime; @property (nonatomic, retain) NSDate *pmTime; @property (nonatomic, retain) IBOutlet UITableView *tbl; @property (nonatomic, retain) IBOutlet UIDatePicker *picker; - (IBAction)timeChange:(id)sender; - (IBAction)pickerChange:(id)sender; - (NSString *)dateAsString: (NSDate *)date; @end </code></pre> <p><strong>NewViewController.m</strong></p> <pre><code>#import "Reminders.h" @interface Reminders () @end @implementation Reminders @synthesize tbl, picker; @synthesize amTime, pmTime; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization NSLog(@"init"); } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"did load"); amTime = [NSDate date]; NSLog(@"AM time viewDidLoad: %@", [self dateAsString:amTime]); pmTime = [NSDate date]; NSLog(@"PM time viewDidLoad: %@", [self dateAsString:pmTime]); selectedRow = (NSInteger)1; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { return 3; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //NSLog(@"cell for row"); UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"MyIdentifier"]; } if (indexPath.row == 0) { cell.textLabel.text = @"Dose"; cell.detailTextLabel.text = @"120"; } else if (indexPath.row == 1) { cell.textLabel.text = @"AM"; //cell.detailTextLabel.text = @"time am"; cell.detailTextLabel.text = [self dateAsString:amTime]; } else if (indexPath.row == 2) { cell.textLabel.text = @"PM"; //cell.detailTextLabel.text = @"time pm"; cell.detailTextLabel.text = [self dateAsString:pmTime]; } if (selectedRow == indexPath.row) { [tbl selectRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0] animated:NO scrollPosition:0]; } return cell; } -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { selectedRow = 0; } else if (indexPath.row == 1) { selectedRow = 1; [picker setDate:amTime]; } else if (indexPath.row == 2) { selectedRow = 2; [picker setDate:pmTime]; } } - (IBAction)timeChange:(id)sender { if (selectedRow == 1) { amTime = [NSDate date]; NSLog(@"time change: %@", [self dateAsString:amTime]); } else if (selectedRow == 2) { pmTime = [NSDate date]; NSLog(@"time change: %@", [self dateAsString:pmTime]); } else { } [tbl reloadData]; } - (IBAction)pickerChange:(id)sender { if (selectedRow == 1) { amTime = [picker date]; NSLog(@"PICKER time change: %@", [self dateAsString:amTime]); } else if (selectedRow == 2) { pmTime = [picker date]; NSLog(@"PICKER time change: %@", [self dateAsString:pmTime]); } else { NSLog(@"picker does NOTHING"); } [tbl reloadData]; } - (NSString *)dateAsString:(NSDate *)date { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *stringFromDate = [formatter stringFromDate:date]; return stringFromDate; } </code></pre> <p>Yes, I totally realize there are actions for both the button and date picker that are altering the times and the reason the button and corresponding action are there is because I started adding things in when I couldn't get it to work the way I thought it should have been working. </p> <p>Anyway. The times seem to start off fine, but are some point are made invalid objective-c objects from what I can see by inspection. It chokes on the cellForRowAtIndexPath method when it tried to put the 'amTime' into the cell detail text.</p> <p>Here's the kicker.... I created the same app, using the same steps I mentioned above, same code (copy pasted), on another machine (one that has proper code signing keys), and that version works properly, even if I run that project on my current machine. When I create the project on my current machine, it crashes.</p> <p>I apologize for the length post but I wanted to try to give as much detail as possible.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload