Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/93.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从删除表视图中的行中获取SIGABRT_Ios_Iphone_Xcode_Uitableview_Sigabrt - Fatal编程技术网

Ios 从删除表视图中的行中获取SIGABRT

Ios 从删除表视图中的行中获取SIGABRT,ios,iphone,xcode,uitableview,sigabrt,Ios,Iphone,Xcode,Uitableview,Sigabrt,我试图让一个表视图列出存储在一个数组中的许多对象,它工作正常,而不是当我试图删除一行时,它抛出一个SIGABRT。我检查了它是否正确地更新了阵列。似乎SIGABRT与表中的节数有关。以下是表视图控制器的代码: CalendarViewController.h #import <UIKit/UIKit.h> #import "Job.h" #import "Shift.h" #import "AppDelegate.h" @interface CalendarViewControll

我试图让一个表视图列出存储在一个数组中的许多对象,它工作正常,而不是当我试图删除一行时,它抛出一个SIGABRT。我检查了它是否正确地更新了阵列。似乎SIGABRT与表中的节数有关。以下是表视图控制器的代码:

CalendarViewController.h

#import <UIKit/UIKit.h>
#import "Job.h"
#import "Shift.h"
#import "AppDelegate.h"

@interface CalendarViewController : UITableViewController

@property (nonatomic, strong) NSMutableArray *currentShiftsList;
@property (nonatomic, strong) AppDelegate *dataCenter;

@end
#导入
#导入“Job.h”
#导入“Shift.h”
#导入“AppDelegate.h”
@界面CalendarViewController:UITableViewController
@属性(非原子,强)NSMutableArray*currentShiftsList;
@属性(非原子,强)AppDelegate*数据中心;
@结束
CalendarViewController.m

#import "CalendarViewController.h"

@interface CalendarViewController ()

@property (nonatomic, strong) NSMutableDictionary *sections;
@property (nonatomic, strong) NSArray *sortedShifts;
@property (strong, nonatomic) NSDateFormatter *sectionDateFormatter;
@property (strong, nonatomic) NSDateFormatter *cellDateFormatter;

@end

@implementation CalendarViewController

@synthesize sections, sortedShifts, currentShiftsList, dataCenter, sectionDateFormatter, cellDateFormatter;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (NSDate *)dateAtBeginningOfDayForDate:(NSDate *)inputDate {

    // Use the user's current calendar and time zone
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSTimeZone *timeZone = [NSTimeZone systemTimeZone];
    [calendar setTimeZone:timeZone];

    // Selectively convert the date components (year, month, day) of the input date
    NSDateComponents *dateComps = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:inputDate];

    // Set the time components manually
    [dateComps setHour:0];
    [dateComps setMinute:0];
    [dateComps setSecond:0];

    // Convert back       
    NSDate *beginningOfDay = [calendar dateFromComponents:dateComps];
    return beginningOfDay;
}

- (NSDate *)dateByAddingYears:(NSInteger)numberOfYears toDate:(NSDate *)inputDate
{
    // Use the user's current calendar
    NSCalendar *calendar = [NSCalendar currentCalendar];

    NSDateComponents *dateComps = [[NSDateComponents alloc] init];
    [dateComps setYear:numberOfYears];

    NSDate *newDate = [calendar dateByAddingComponents:dateComps toDate:inputDate options:0];
    return newDate;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    dataCenter = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    currentShiftsList = [[NSMutableArray alloc] initWithArray:dataCenter.shiftsList];

    self.sectionDateFormatter = [[NSDateFormatter alloc] init];
    [self.sectionDateFormatter setDateStyle:NSDateFormatterLongStyle];
    [self.sectionDateFormatter setTimeStyle:NSDateFormatterNoStyle];

    self.cellDateFormatter = [[NSDateFormatter alloc] init];
    [self.cellDateFormatter setDateStyle:NSDateFormatterNoStyle];
    [self.cellDateFormatter setTimeStyle:NSDateFormatterShortStyle];

    // 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;

    self.sections = [NSMutableDictionary dictionary];
    for (Shift *shift in dataCenter.shiftsList) {

        // Reduce event start date to date components (year, month, day)
        NSDate *dateRepresentingThisDay = [self dateAtBeginningOfDayForDate:shift.startDate];

        // If we don't yet have an array to hold the events for this day, create one
        NSMutableArray *shiftsOnThisDay = [self.sections objectForKey:dateRepresentingThisDay];
        if (shiftsOnThisDay == nil) {
            shiftsOnThisDay = [NSMutableArray array];

            // Use the reduced date as dictionary key to later retrieve the event list this day
            [self.sections setObject:shiftsOnThisDay forKey:dateRepresentingThisDay];
        }

        // Add the event to the list for this day
        [shiftsOnThisDay addObject:shift];
    }

    // Create a sorted list of days
    NSArray *unsortedShifts = [self.sections allKeys];
    self.sortedShifts = [unsortedShifts sortedArrayUsingSelector:@selector(compare:)];
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return [self.sections count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    NSDate *dateRepresentingThisDay = [self.sortedShifts objectAtIndex:section];
    NSArray *eventsOnThisDay = [self.sections objectForKey:dateRepresentingThisDay];
    return [eventsOnThisDay count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *reuseIdentifier = @"shifts";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];

    NSDate *dateRepresentingThisDay = [self.sortedShifts objectAtIndex:indexPath.section];
    NSArray *eventsOnThisDay = [self.sections objectForKey:dateRepresentingThisDay];
    Shift *shift = [eventsOnThisDay objectAtIndex:indexPath.row];

    cell.textLabel.text = shift.jobtitle;

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"h:mm a"];

    NSString *start = [formatter stringFromDate:shift.startDate];
    NSString *end = [formatter stringFromDate:shift.endDate];

    NSString *detail = [[NSString alloc] initWithFormat:@"%@ to %@", start, end];
    cell.detailTextLabel.text = detail;
    return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSDate *dateRepresentingThisDay = [self.sortedShifts objectAtIndex:section];
    return [self.sectionDateFormatter stringFromDate:dateRepresentingThisDay];
}

/*
// 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

        [currentShiftsList removeObjectAtIndex:indexPath.row];
        dataCenter.shiftsList = currentShiftsList;

        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject: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 - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end
#导入“CalendarViewController.h”
@接口CalendarViewController()
@属性(非原子,强)NSMutableDictionary*节;
@属性(非原子、强)NSArray*分类移位;
@属性(强,非原子)NSDateFormatter*sectionDateFormatter;
@属性(强,非原子)NSDateFormatter*cellDateFormatter;
@结束
@实现日历视图控制器
@合成区段、分类移位、currentShiftsList、数据中心、区段日期格式化程序、cellDateFormatter;
-(id)initWithStyle:(UITableViewStyle)样式
{
self=[super initWithStyle:style];
如果(自我){
//自定义初始化
}
回归自我;
}
-(NSDate*)日期起始日期FDAYFORDATE:(NSDate*)输入日期{
//使用用户的当前日历和时区
NSCalendar*日历=[NSCalendar currentCalendar];
NSTimeZone*时区=[NSTimeZone systemTimeZone];
[日历设置时区:时区];
//有选择地转换输入日期的日期组件(年、月、日)
NSDateComponents*dateComps=[日历组件:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:inputDate];
//手动设置时间组件
[dateComps设置小时:0];
[dateComps设置分钟:0];
[dateComps设置秒:0];
//折回
NSDate*beginingofday=[calendar dateFromComponents:dateComps];
返回起始日期;
}
-(NSDate*)日期通过添加年份:(NSInteger)截止日期的年份数:(NSDate*)输入日期
{
//使用用户的当前日历
NSCalendar*日历=[NSCalendar currentCalendar];
NSDateComponents*dateComps=[[NSDateComponents alloc]init];
[dateComps设置年份:numberOfYears];
NSDate*newDate=[日历日期由AddingComponents:dateComps toDate:inputDate选项:0];
返回newDate;
}
-(无效)viewDidLoad
{
[超级视图下载];
数据中心=(AppDelegate*)[[UIApplication sharedApplication]委托];
currentShiftsList=[[NSMutableArray alloc]initWithArray:dataCenter.shiftsList];
self.sectionDateFormatter=[[NSDateFormatter alloc]init];
[self.sectionDateFormatter setDateStyle:NSDateFormatterLongStyle];
[self.sectionDateFormatter setTimeStyle:NSDateFormatterNoStyle];
self.cellDateFormatter=[[NSDateFormatter alloc]init];
[self.cellDateFormatter setDateStyle:NSDateFormatterNoStyle];
[self.cellDateFormatter setTimeStyle:NSDateFormatterShortStyle];
//取消对下一行的注释以保留演示文稿之间的选择。
//self.clearselectiononviewwillappear=否;
//取消对以下行的注释,以在此视图控制器的导航栏中显示编辑按钮。
self.navigationItem.rightBarButtonItem=self.editButtonItem;
self.sections=[NSMutableDictionary];
用于(数据中心中的班次*班次。班次列表){
//将事件开始日期减少为最新组件(年、月、日)
NSDate*dateRepresentingThisDay=[开始时的自日期fdayfordate:shift.startDate];
//如果我们还没有一个数组来保存这一天的事件,那么创建一个数组
NSMUTABLEARRY*shiftsOnThisDay=[self.sections objectForKey:dateRepresentingThisDay];
if(shiftsOnThisDay==nil){
shiftsOnThisDay=[NSMutableArray];
//使用缩减的日期作为字典键,以便稍后检索当天的事件列表
[self.setObject:shiftsOnThisDay-forKey:dateRepresentingThisDay];
}
//将事件添加到当天的列表中
[shiftsOnThisDay addObject:shift];
}
//创建已排序的天数列表
NSArray*unsortedShift=[self.sections allkey];
self.sortedShift=[UnsortedShift-sortedDarrayusingSelector:@selector(compare:)];
}
-(无效)视图卸载
{
[超级视频下载];
//释放主视图的所有保留子视图。
//例如,self.myOutlet=nil;
}
-(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation
{
返回(interfaceOrientation==UIInterfaceOrientationGraphic);
}
#pragma标记-表视图数据源
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回节数。
返回[self.sections count];
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
//返回节中的行数。
NSDate*dateRepresentingThisDay=[self.sortedShift对象索引:节];
NSArray*events sonthis day=[self.sections objectForKey:daterepresentingthis day];
返回[当天的事件计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
NSString*reuseIdentifier=@“移位”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
NSDate*dateRepresentingThisDay=[self.sortedShifts objectAtIndex:indexPath.section];
NSArray*events sonthis day=[self.sections objectForKey:daterepresentingthis day];
Shift*Shift=[EventsOnThistDay对象索引:indexath.row];
cell.textlab.text=shift.jobtitle;
NSDateFormatter*格式化程序=[[NSDateFormatter alloc]init];
[格式化程序setDateFormat:@“h:mm a”];
NSString*start=[formatter stringFromDate:shift.startDate];
NSString*end=[f
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView deleteRowsAtIndexPaths:indexPath.row withRowAnimation:UITableViewRowAnimationFade];