Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.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
Xcode 从UITableview选择数据时应用程序崩溃_Xcode_Uitableview_Selection_Cell_Core - Fatal编程技术网

Xcode 从UITableview选择数据时应用程序崩溃

Xcode 从UITableview选择数据时应用程序崩溃,xcode,uitableview,selection,cell,core,Xcode,Uitableview,Selection,Cell,Core,我四处搜索,但找不到任何与我的问题有关的东西。我有一个应用程序,可以将保存的游戏对象数组加载到UITableview。我可以很好地保存和浏览应用程序的所有其他部分,除非我尝试单击一个过去的游戏来加载将显示其中数据的视图。我使用了本教程:(http://timroadley.com/2012/02/12/core-data-basics-part-2-core-data-views/)当我把我的游戏名加载到一个随机的标签上时,我把它改编成我的代码,让它工作。我所做的最大改变是,单击单元格后应显示的

我四处搜索,但找不到任何与我的问题有关的东西。我有一个应用程序,可以将保存的游戏对象数组加载到UITableview。我可以很好地保存和浏览应用程序的所有其他部分,除非我尝试单击一个过去的游戏来加载将显示其中数据的视图。我使用了本教程:(http://timroadley.com/2012/02/12/core-data-basics-part-2-core-data-views/)当我把我的游戏名加载到一个随机的标签上时,我把它改编成我的代码,让它工作。我所做的最大改变是,单击单元格后应显示的“过去的游戏记分卡”视图不再是tableview的委托。我还添加了更多属性,并在完成此操作后刷新了NSManagedObject子类。如果我需要显示更多代码,请告诉我

以下是TableView的.m代码:

#import "PastGames.h"
#import "Game.h"

@interface PastGames ()

@end

@implementation PastGames

@synthesize fetchedResultsController = __fetchedResultsController;
@synthesize managedObjectContext = __managedObjectContext;
@synthesize selectedGame;


- (void)setupFetchedResultsController
{
    // 1 - Decide what Entity you want
    NSString *entityName = @"Game"; // Put your entity name here
    NSLog(@"Setting up a Fetched Results Controller for the Entity named %@", entityName);

    // 2 - Request that Entity
    NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:entityName];

    // 3 - Filter it if you want
    //request.predicate = [NSPredicate predicateWithFormat:@"Role.name = Blah"];

    // 4 - Sort it if you want
    request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"name"
                                                                                     ascending:YES
                                                                                      selector:@selector(localizedCaseInsensitiveCompare:)]];
    // 5 - Fetch it
    self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
                                                                        managedObjectContext:self.managedObjectContext
                                                                          sectionNameKeyPath:nil
                                                                                   cacheName:nil];
    [self performFetch];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self setupFetchedResultsController];
}

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

- (void)viewDidLoad
{
    [super viewDidLoad];

    // 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)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

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





- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Game Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    Game *game = [self.fetchedResultsController objectAtIndexPath:indexPath];
    cell.textLabel.text = game.name;
    cell.detailTextLabel.text = game.date;
    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) 
    {

        [self.tableView beginUpdates]; // Avoid  NSInternalInconsistencyException

        // Delete the role object that was swiped
        Game *gameToDelete = [self.fetchedResultsController objectAtIndexPath:indexPath];
        NSLog(@"Deleting (%@)", gameToDelete.name);
        [self.managedObjectContext deleteObject:gameToDelete];
        [self.managedObjectContext save:nil];

        // Delete the (now empty) row on the table
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self performFetch];

        [self.tableView endUpdates];
    } 
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{

    if ([segue.identifier isEqualToString:@"Show Game Segue"])
    {
        NSLog(@"Setting PastGames as a delegate of PastGameScoreCard");
        PastGameScoreCard *pastGameScoreCard = segue.destinationViewController;

        pastGameScoreCard.managedObjectContext = self.managedObjectContext;

        // Store selected Game in selectedGame property
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        self.selectedGame = [self.fetchedResultsController objectAtIndexPath:indexPath];

        NSLog(@"Passing selected game (%@) to PastGameScoreCard", self.selectedGame.name);
        pastGameScoreCard.game = self.selectedGame;
        NSLog(@"Success!");
    }
    else 
    {
        NSLog(@"Unidentified Segue Attempted!");
    }
}



@end
以下是应显示并加载该游戏数据的视图的.m文件PastGameScorrecard:

#import "PastGameScoreCard.h"

@interface PastGameScoreCard ()

@end

@implementation PastGameScoreCard
//Player Names
@synthesize frontOrBack;
@synthesize holeNumbers;
@synthesize p1NameLabel;
@synthesize p2NameLabel;
@synthesize p3NameLabel;
@synthesize p4NameLabel;

//Player 1
@synthesize p1Hole1and10Label;
@synthesize p1Hole2and11Label;
@synthesize p1Hole3and12Label;
@synthesize p1Hole4and13Label;
@synthesize p1Hole5and14Label;
@synthesize p1Hole6and15Label;
@synthesize p1Hole7and16Label;
@synthesize p1Hole8and17Label;
@synthesize p1Hole9and18Label;
@synthesize p1TotalLabel;

//Player 2
@synthesize p2Hole1and10Label;
@synthesize p2Hole2and11Label;
@synthesize p2Hole3and12Label;
@synthesize p2Hole4and13Label;
@synthesize p2Hole5and14Label;
@synthesize p2Hole6and15Label;
@synthesize p2Hole7and16Label;
@synthesize p2Hole8and17Label;
@synthesize p2Hole9and18Label;
@synthesize p2TotalLabel;

//Player 3
@synthesize p3Hole1and10Label;
@synthesize p3Hole2and11Label;
@synthesize p3Hole3and12Label;
@synthesize p3Hole4and13Label;
@synthesize p3Hole5and14Label;
@synthesize p3Hole6and15Label;
@synthesize p3Hole7and16Label;
@synthesize p3Hole8and17Label;
@synthesize p3Hole9and18Label;
@synthesize p3TotalLabel;

//Player 4
@synthesize p4Hole1and10Label;
@synthesize p4Hole2and11Label;
@synthesize p4Hole3and12Label;
@synthesize p4Hole4and13Label;
@synthesize p4Hole5and14Label;
@synthesize p4Hole6and15Label;
@synthesize p4Hole7and16Label;
@synthesize p4Hole8and17Label;
@synthesize p4Hole9and18Label;
@synthesize p4TotalLabel;


@synthesize managedObjectContext = __managedObjectContext;
@synthesize game = _game;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}




- (void)viewDidLoad
{
    NSLog(@"Setting the value of fields in this static table to that of the passed Game");


    //Player 1
    self.p1NameLabel.text = self.game.p1Name;
    self.p1Hole1and10Label.text = self.game.p1h1;
    self.p1Hole2and11Label.text = self.game.p1h2;
    self.p1Hole3and12Label.text = self.game.p1h3;
    self.p1Hole4and13Label.text = self.game.p1h4;
    self.p1Hole5and14Label.text = self.game.p1h5;
    self.p1Hole6and15Label.text = self.game.p1h6;
    self.p1Hole7and16Label.text = self.game.p1h7;
    self.p1Hole8and17Label.text = self.game.p1h8;
    self.p1Hole9and18Label.text = self.game.p1h9;
    self.p1TotalLabel.text = self.game.p1Total;

    //Player 2
    self.p2NameLabel.text = self.game.p2Name;
    self.p2Hole1and10Label.text = self.game.p2h1;
    self.p2Hole2and11Label.text = self.game.p2h2;
    self.p2Hole3and12Label.text = self.game.p2h3;
    self.p2Hole4and13Label.text = self.game.p2h4;
    self.p2Hole5and14Label.text = self.game.p2h5;
    self.p2Hole6and15Label.text = self.game.p2h6;
    self.p2Hole7and16Label.text = self.game.p2h7;
    self.p2Hole8and17Label.text = self.game.p2h8;
    self.p2Hole9and18Label.text = self.game.p2h9;
    self.p2TotalLabel.text = self.game.p2Total;

    //Player 3
    self.p3NameLabel.text = self.game.p3Name;
    self.p3Hole1and10Label.text = self.game.p3h1;
    self.p3Hole2and11Label.text = self.game.p3h2;
    self.p3Hole3and12Label.text = self.game.p3h3;
    self.p3Hole4and13Label.text = self.game.p3h4;
    self.p3Hole5and14Label.text = self.game.p3h5;
    self.p3Hole6and15Label.text = self.game.p3h6;
    self.p3Hole7and16Label.text = self.game.p3h7;
    self.p3Hole8and17Label.text = self.game.p3h8;
    self.p3Hole9and18Label.text = self.game.p3h9;
    self.p3TotalLabel.text = self.game.p3Total;

    //Player 4
    self.p4NameLabel.text = self.game.p4Name;
    self.p4Hole1and10Label.text = self.game.p4h1;
    self.p4Hole2and11Label.text = self.game.p4h2;
    self.p4Hole3and12Label.text = self.game.p4h3;
    self.p4Hole4and13Label.text = self.game.p4h4;
    self.p4Hole5and14Label.text = self.game.p4h5;
    self.p4Hole6and15Label.text = self.game.p4h6;
    self.p4Hole7and16Label.text = self.game.p4h7;
    self.p4Hole8and17Label.text = self.game.p4h8;
    self.p4Hole9and18Label.text = self.game.p4h9;
    self.p4TotalLabel.text = self.game.p4Total;




    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

/*
//When view appears, show front 9 scores
- (void)viewDidAppear: (BOOL)animated 
{
    [super viewDidAppear: animated];

    //Sets name of course in game object to title.
    self.title = self.game.name;
}
 */



- (void)viewDidUnload
{

    [self setP1Hole4and13Label:nil];
    [self setP1Hole5and14Label:nil];
    [self setP1Hole6and15Label:nil];
    [self setP1Hole7and16Label:nil];
    [self setP1Hole8and17Label:nil];
    [self setP1Hole9and18Label:nil];
    [self setP1TotalLabel:nil];
    [self setP2Hole1and10Label:nil];
    [self setP2Hole2and11Label:nil];
    [self setP2Hole3and12Label:nil];
    [self setP2Hole4and13Label:nil];
    [self setP2Hole5and14Label:nil];
    [self setP2Hole6and15Label:nil];
    [self setP2Hole7and16Label:nil];
    [self setP2Hole8and17Label:nil];
    [self setP2Hole9and18Label:nil];
    [self setP2TotalLabel:nil];
    [self setP3Hole1and10Label:nil];
    [self setP3Hole2and11Label:nil];
    [self setP3Hole3and12Label:nil];
    [self setP3Hole4and13Label:nil];
    [self setP3Hole5and14Label:nil];
    [self setP3Hole6and15Label:nil];
    [self setP3Hole7and16Label:nil];
    [self setP3Hole8and17Label:nil];
    [self setP3Hole9and18Label:nil];
    [self setP3TotalLabel:nil];
    [self setP4Hole1and10Label:nil];
    [self setP4Hole2and11Label:nil];
    [self setP4Hole3and12Label:nil];
    [self setP4Hole4and13Label:nil];
    [self setP4Hole5and14Label:nil];
    [self setP4Hole6and15Label:nil];
    [self setP4Hole7and16Label:nil];
    [self setP4Hole8and17Label:nil];
    [self setP4Hole9and18Label:nil];
    [self setP4TotalLabel:nil];
    [self setHoleNumbers:nil];
    [self setFrontOrBack:nil];

    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

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




@end

同样,只有当我点击保存了游戏的单元格时,应用程序才会崩溃,它应该显示一个记分卡视图,其中包含从保存的核心数据加载到标签中的所有数据。

查看崩溃报告会有帮助吗?请下次发布相关代码,我启用了异常断点,但这次崩溃显示的是我的主.m文件。解决了它,代码没有问题,但实际项目本身有问题。谢谢Dweebo,如果你的问题被解决了,这个问题对任何人都毫无价值(而且没有,即使我们甚至不知道问题是什么),你也应该考虑删除你的问题。或者至少,发表你自己的答案并接受它。否则,这将显示为一个未回答的问题,人们会浪费时间来研究它。