Thread 1, Queue : com.apple.main-thread.
iMac, OS X Mavericks (10.9.1)
iMac, OS X Mavericks (10.9.1)
Scroll the debugger output (the pane at the bottom showing text "18 ToDoList") to find the exception that caused the SIGABRT. Paste the text here. If the exception references a position in your code, paste the code also.
Thanks Llessur999,
I started again and it seemed to work next time? Guess I need to be more rigorous.
What's happening now is when I tap a ToDoItem the checkmark appears in another cell?
Here's the code if you get a chance to look. Thanks
//
// XYZToDoListViewController.m
// TFC
//
// Created by Paul Shenton on 22/01/2014.
// Copyright (c) 2014 Paul Shenton. All rights reserved.
//
#import "XYZToDoListViewController.h"
#import "XYZToDoItem.h"
@interfaceXYZToDoListViewController ()
@propertyNSMutableArray *toDoItems;
@end
@implementation XYZToDoListViewController
- (void) loadInitialData {
XYZToDoItem *item1 = [[XYZToDoItemalloc] init];
item1.itemName = @"Buy Milk";
[self.toDoItems addObject:item1];
XYZToDoItem *item2 = [[XYZToDoItemalloc] init];
item2.itemName = @"Buy beer";
[self.toDoItems addObject:item2];
XYZToDoItem *item3 = [[XYZToDoItemalloc] init];
item3.itemName = @"Buy car";
[self.toDoItems addObject:item3];
XYZToDoItem *item4 = [[XYZToDoItemalloc] init];
item4.itemName = @"Sell car";
[self.toDoItems addObject:item4];
}
- (IBAction)unwindToList: (UIStoryboardSegue *) segue
{
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
returnself;
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.toDoItems = [[NSMutableArray alloc]init];
[selfloadInitialData];
// Uncomment the following line to preserve selection between presentations.
//self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.toDoItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ListPrototypeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row];
cell.textLabel.text = toDoItem.itemName;
if (toDoItem.completed) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
/*
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
XYZToDoItem *tappedItem = [self.toDoItems objectAtIndex:indexPath.row];
tappedItem.completed = !tappedItem.completed;
[tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
@end
You are handling didDeselectRowAtIndexPath so it is using the index path of the previously selected row. Instead you should hande didSelectRowAtIndexPath.
After you make this change, you will notice the selection indicator (blue background) does not flash. The user typically expects this feedback. In reloadRowsAtIndexPaths, specify UITableViewRowAnimationAutomatic. The deselectRowAtIndexPath is unnecessary.
Many thanks indeed 🙂
/this is the error ?
0x1f33167: cmpl $-0x1, %eax
Thread 1, Queue : com.apple.main-thread.