gpt4 book ai didi

ios - EXC_BAD_ACCESS- 返回导航 Controller 时崩溃

转载 作者:行者123 更新时间:2023-11-28 22:00:51 26 4
gpt4 key购买 nike

所以我很难找出我的程序崩溃的原因。到目前为止,我有一个主屏幕,它转到带有两个选项卡的 UITabBar,每个选项卡都有 UITableView。在第二个选项卡上,我有一个自定义单元格,如果用户单击它,该单元格应该会提供更多详细信息。所有这些都在 UINavigationController 中。当我在带有表格单元格详细信息的 View Controller 中时,按回车键,然后再次按回车键(我应该在主屏幕上),程序在这里崩溃并显示 EXC_BAD_ACCESS(代码 = 1):

int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([RaceMeAppDelegate class])); //EXC_BAD_ACCESS }
}

通过查看其他帖子,我尝试使用 Xcode 中的僵尸工具来找出问题所在。我运行了它,它说“一个 objective-c 消息被发送到一个地址为 0x16f19370 的已释放的“MatchCellDetailsViewController”对象(僵尸)。日志看起来像这样:

#   Event Type  ∆ RefCt RefCt   Timestamp   Responsible Library Responsible Caller
0 Malloc +1 1 00:14.422.351 UIKit -[UIClassSwapper initWithCoder:]
1 Retain +1 2 00:14.430.802 UIKit UINibDecoderDecodeObjectForValue
2 Retain +1 3 00:14.431.402 UIKit -[UIRuntimeConnection initWithCoder:]
3 Retain +1 4 00:14.431.488 UIKit -[UIRuntimeConnection initWithCoder:]
4 Retain +1 5 00:14.431.977 UIKit UINibDecoderDecodeObjectForValue
5 Retain +1 6 00:14.432.136 UIKit UINibDecoderDecodeObjectForValue
6 Retain +1 7 00:14.432.310 Foundation -[NSObject(NSKeyValueCoding) setValue:forKeyPath:]
7 Retain +1 8 00:14.432.639 UIKit -[UINib instantiateWithOwner:options:]
8 Release -1 7 00:14.432.964 UIKit -[UINibDecoder finishDecoding]
Release (2) -2 00:14.433.013 UIKit -[UINibDecoder finishDecoding]
10 Release -1 5 00:14.433.134 UIKit -[UINibDecoder finishDecoding]
11 Release -1 4 00:14.433.176 UIKit -[UIRuntimeConnection dealloc]
12 Release -1 3 00:14.433.341 UIKit -[UIRuntimeConnection dealloc]
14 Retain +1 3 00:14.434.055 UIKit -[UIStoryboardSegue initWithIdentifier:source:destination:]
Retain/Release (2) 00:14.434.138 RaceMe -[ReceivedTabTableViewController prepareForSegue:sender:]
17 Retain +1 4 00:14.436.369 UIKit -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:]
Retain/Autorelease/Release (3) 00:14.437.924 UIKit -[UINavigationController topViewController]
Retain/Autorelease/Release (3) 00:14.438.033 UIKit -[UINavigationController topViewController]
Retain/Release (2) 00:14.438.158 UIKit -[UINavigationController pushViewController:transition:forceImmediate:]
Retain/Autorelease/Release (3) 00:14.465.975 UIKit -[UINavigationController topViewController]
25 Retain +1 9 00:14.466.037 libsystem_blocks.dylib _Block_object_assign
26 Retain +1 10 00:14.467.423 UIKit -[UINavigationController topViewController]
27 Autorelease 00:14.467.430 UIKit -[UINavigationController _startDeferredTransitionIfNeeded:]
28 Retain +1 11 00:14.467.467 UIKit -[UINavigationController topViewController]
29 Autorelease 00:14.467.475 UIKit -[UINavigationController _startCustomTransition:]
30 Retain +1 12 00:14.477.542 UIKit -[UINib instantiateWithOwner:options:]
31 Retain +1 13 00:14.484.362 UIKit -[UINib instantiateWithOwner:options:]
32 Retain +1 14 00:14.484.481 UIKit -[UINib instantiateWithOwner:options:]
33 Retain +1 15 00:14.484.582 UIKit +[UIProxyObject addMappings:forCoder:]
34 Retain +1 16 00:14.493.202 UIKit -[UIProxyObject initWithCoder:]
Retain/Release (12) 00:14.493.229 UIKit -[UIRuntimeConnection initWithCoder:]
Retain (4) +4 00:14.494.155 UIKit -[UIRuntimeConnection initWithCoder:]
40 Retain +1 22 00:14.498.045 UIKit -[UIProxyObject initWithCoder:]
46 Release -1 26 00:14.505.411 UIKit -[UINib instantiateWithOwner:options:]
Release (4) -4 00:14.506.686 UIKit -[UINibDecoder finishDecoding]
Release (4) -4 00:14.507.340 UIKit -[UIRuntimeConnection dealloc]
61 Release -1 11 00:14.509.718 Foundation -[NSAutoreleasePool drain]
62 Retain +1 12 00:14.513.293 UIKit -[UINavigationController topViewController]
63 Autorelease 00:14.513.308 UIKit -[UINavigationController _startCustomTransition:]
Retain/Release (2) 00:14.513.330 UIKit -[UINavigationController _startCustomTransition:]
66 Retain +1 13 00:14.513.399 UIKit -[UINavigationController topViewController]
67 Autorelease 00:14.513.407 UIKit -[UINavigationController _startCustomTransition:]
68 Retain +1 14 00:14.513.477 UIKit -[UINavigationController _startCustomTransition:]
69 Release -1 13 00:14.513.642 UIKit -[UINavigationController _startCustomTransition:]
Retain/Autorelease/Release (3) 00:14.514.475 UIKit -[UINavigationController topViewController]
72 Retain +1 15 00:14.719.975 libsystem_blocks.dylib _Block_object_assign
Retain/Autorelease/Release (3) 00:14.722.535 UIKit -[UINavigationController topViewController]
Retain/Release (2) 00:14.723.110 UIKit -[UIResponder becomeFirstResponder]
77 Release -1 15 00:14.762.974 libsystem_blocks.dylib _Block_release
Release (3) -3 00:15.145.440 QuartzCore CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*)
84 Release -1 8 00:15.146.309 UIKit _wrapRunLoopWithAutoreleasePoolHandler
87 Release -1 5 00:15.147.134 UIKit -[UIStoryboardSegue dealloc]
88 Release -1 4 00:15.147.183 UIKit _wrapRunLoopWithAutoreleasePoolHandler
89 Release -1 3 00:15.147.322 UIKit -[UIStoryboardScene dealloc]
90 Retain +1 4 00:15.385.010 UIKit -[UINavigationController topViewController]
91 Autorelease 00:15.385.017 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
Retain/Autorelease/Release (3) 00:15.429.329 UIKit -[UINavigationController topViewController]
94 Retain +1 6 00:15.431.214 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
Release (2) -2 00:15.431.373 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
97 Release -1 3 00:15.433.236 UIKit __destroy_helper_block_119
98 Release -1 2 00:15.433.615 GraphicsServices GSEventRunModal
Retain/Autorelease/Release (3) 00:15.792.024 UIKit -[UINavigationController topViewController]
Retain/Autorelease/Release (3) 00:15.792.321 UIKit -[UINavigationController topViewController]
Retain/Autorelease/Release (6) 00:15.792.807 UIKit -[UINavigationController topViewController]
Retain/Release (2) 00:15.792.878 UIKit -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:]
Release/Retain (2) 00:15.792.899 UIKit _popViewControllerNormal
Retain/Release (2) 00:15.793.576 UIKit _popViewControllerNormal
Retain/Release (8) 00:15.824.455 UIKit -[UINavigationController _startCustomTransition:]
124 Retain +1 4 00:16.554.694 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
126 Retain +1 4 00:16.555.120 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
128 Release -1 2 00:16.555.354 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
130 Release -1 0 00:16.559.291 UIKit __destroy_helper_block_119
131 Zombie -1 00:18.098.937 UIKit -[UINavigationController _startCustomTransition:]

我试着看看我是否在我不应该调用的地方调用了 MatchCellDetailsViewController,但是我找不到我在哪里使用了这个类并且会导致问题。第二个选项卡是 MatchCellDetailsViewController 的委托(delegate),因此我可以向后传递数据,但除此之外,我认为我没有进行任何错误的调用。我不太确定 _startCustomTransition 指的是什么。

如果您能帮助我们找出问题所在,我们将不胜感激。谢谢

----编辑----

我认为问题出在这两个类中的某处,我尝试发布代码的更相关部分。

ReceivedTabBarViewController.m(主屏转到这个)

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView reloadData]; //necessary to reload if user switches between tabs
}
- (void)viewDidLoad
{
[super viewDidLoad];

[self loadMatchesWithCallback:^(NSArray *matches) {
self.matches = matches;
self.matchesMutable = [NSMutableArray arrayWithArray:self.matches];
[self.activityIndicator startAnimating];

if ([self.matches count] == 0) { [self.activityIndicator stopAnimating]; }

for (GKTurnBasedMatch *match in self.matches) {
//Gets the match data
[self loadAndDisplayMatchDataWithCallback:match callback:^(NSData *matchData) {
RaceMeGame *updatedGame = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
NSString *matchDataString = [NSString stringWithFormat:@"%@ %@ %@ %d", updatedGame.matchDistance, updatedGame.status, updatedGame.score, updatedGame.numberOfTurns];
[self.matchWithMatchData setObject:matchDataString forKey:match.matchID];

NSLog(@"Match data: %@", matchDataString);
NSLog(@"Current number of turns: %d", updatedGame.numberOfTurns);

//Converts the matchID to a GKTurnBasedMatch
[self retrieveMatch:match.matchID callback:^(GKTurnBasedMatch *match) {

GKTurnBasedParticipant *currentPlayerInMatch = [match currentParticipant];
NSArray *currentPlayerIDs = [[NSArray alloc] initWithObjects:currentPlayerInMatch.playerID, nil];

//Converts a player ID to a player's alias
[self retrievePlayerAliases:currentPlayerIDs callback:^(NSArray *players) {

[self.currentPlayerTurnAliasList addObject:((GKPlayer*)[players firstObject]).alias];

if ([self.currentPlayerTurnAliasList count] == [self.matches count]) {
[self.tableView reloadData];
[self.activityIndicator stopAnimating];
}
}];

}];
}];
}
}];
}

- (void)removeReceivedChallenge:(NSInteger)index
{
GKTurnBasedMatch *match = [self.matchesMutable objectAtIndex:index];

//Remove the data from table
[self.matchWithMatchData removeObjectForKey:match.matchID];
[self.matchesMutable removeObjectAtIndex:(NSUInteger)index];

NSIndexPath *myIP = [NSIndexPath indexPathForRow:index inSection:0];

[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:myIP] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}

#pragma mark - MatchCellDetailsViewController Delegate
- (void)indexRemoveViewController:(MatchCellDetailsViewController *)controller didFinishRemovingIndex:(NSInteger)index
{
[self removeReceivedChallenge:index];
}

- (void)moveChallengeToCurrentViewController:(MatchCellDetailsViewController *)controller didFinishMoving:(GKTurnBasedMatch*)match
{
GlobalVars *globals = [GlobalVars sharedInstance];
RaceMeGame *updatedGame = [NSKeyedUnarchiver unarchiveObjectWithData:match.matchData];

NSArray *currentPlayerIDs = [[NSArray alloc] initWithObjects:match.currentParticipant.playerID, nil];
[self retrievePlayerAliases:currentPlayerIDs callback:^(NSArray *players) {

[globals.currentMatches setObject:[[NSDictionary alloc]
initWithObjectsAndKeys:updatedGame.status, ((GKPlayer*)[players firstObject]).alias, nil]
forKey:match.matchID];

if (![globals.currentMatchesHelper containsObject:match.matchID]) {
[globals.currentMatchesHelper addObject:match.matchID];
}

}];

}

#pragma mark - Navigation

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"ShowReceivedChallengeDetails"]) {
MatchCellDetailsViewController *detailViewController = [segue destinationViewController];
NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
long row = [myIndexPath row];

//Distance-Status-Score-NumberOfTurns
NSString *tempMatchString = [self.matchWithMatchData objectForKey:((GKTurnBasedMatch *)[self.matchesMutable objectAtIndex:row]).matchID];
NSArray *tempMatchArrayData = [tempMatchString componentsSeparatedByString:@" "];

detailViewController.distance = [NSString stringWithFormat:@"Distance: %@", [tempMatchArrayData objectAtIndex:0]];
detailViewController.status = [NSString stringWithFormat:@"Game Status: %@", [tempMatchArrayData objectAtIndex:1]];
detailViewController.participant = [NSString stringWithFormat:@"Current Players Turn: %@", [self.currentPlayerTurnAliasList objectAtIndex:row]];
detailViewController.currentNumberOfTurns = [[tempMatchArrayData objectAtIndex:3] intValue];

detailViewController.match = [self.matchesMutable objectAtIndex:row];
detailViewController.rowSelected = (NSInteger)row;
detailViewController.delegate = self;
}
}

MatchCellDetailsViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.delegate = self;
self.distanceLabel.text = self.distance;
self.statusLabel.text = self.status;
self.currentPlayersLabel.text = self.participant;
}

- (IBAction)acceptInvite:(UIButton *)sender {

[self.match acceptInviteWithCompletionHandler:^(GKTurnBasedMatch *match, NSError *error) {
if (error) {
}
else {
if (self.currentNumberOfTurns == 1) {
//advance turn back to the other user
[GameCenterHelper sharedInstance].currentMatch = match;
NSLog(@"Advancing turn");

/***** Preparation to advance turn ******/

//Converting game to NSData and sending it as match data
if ([[GameCenterHelper sharedInstance].currentMatch.matchData bytes] == 0) {
NSLog(@"Match data not created yet, allocating and initializing it");
[GameCenterHelper sharedInstance].gameData = [[RaceMeGame alloc] init];
[[GameCenterHelper sharedInstance] advanceTurn];


NSInteger index = self.rowSelected;
NSLog(@"Index being passed: %d", index);
[self.delegate indexRemoveViewController:self didFinishRemovingIndex:index];

[self.delegate moveChallengeToCurrentViewController:self didFinishMoving:match];


} else {
[[GameCenterHelper sharedInstance] loadAndDisplayMatchDataWithCallback:[GameCenterHelper sharedInstance].currentMatch callback:^(NSData *matchData) {
[GameCenterHelper sharedInstance].gameData = [NSKeyedUnarchiver unarchiveObjectWithData:matchData];
[[GameCenterHelper sharedInstance] advanceTurn];


//Remove this cell from ReceivedChallengesVC
NSInteger index = self.rowSelected;
[self.delegate indexRemoveViewController:self didFinishRemovingIndex:index];

//Send the data to CurrentMatchesVC
//Moves the challenge that the player has accepted the invite to from ReceivedChallengesVC to CurrentChallengesVC
[self.delegate moveChallengeToCurrentViewController:self didFinishMoving:match];
}];
}

} else {
NSLog(@“Error: %@“, error);
}
}
}];

}

最佳答案

Swift iOS:僵尸 UIKit [UINavigationController _startCustomTransition:]我正在使用以下产生错误的代码:

override func viewDidLoad() {
super.viewDidLoad()

self.navigationController?.delegate = self

}// end viewDidLoad

但是一旦我更改了 View 中的委托(delegate),它就会开始工作而没有任何崩溃

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)

self.navigationController?.delegate = self
}

关于ios - EXC_BAD_ACCESS- 返回导航 Controller 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25146694/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com