我知道之前已经问过这个问题,但我无法弄清楚为什么会这样。似乎有很多原因导致这种情况发生。
当我在其中一个视图上单击一个按钮(称为下一个)时会发生这种情况。我会给你视图的代码和它后面的视图。这是不游戏应用程序,尽管有一些观点的名称。
PSANewGame.m
#import "PSANewGame.h"
#import "PSAGlobal.h"
@interface PSANewGame ()
- (IBAction)next:(id)sender;
@end
@implementation PSANewGame
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_player1Name release];
[_player2Name release];
[_player3Name release];
[_player4Name release];
[_player5Name release];
[_player6Name release];
[super dealloc];
}
- (IBAction)next:(id)sender { //This is the button that is being clicked when the SIGBARt occurs.
PSAGlobal *global = [PSAGlobal getInstance];
global.player1Name = self.player1Name.text;
global.player2Name = self.player2Name.text;
global.player3Name = self.player3Name.text;
global.player4Name = self.player4Name.text;
global.player5Name = self.player5Name.text;
global.player6Name = self.player6Name.text;
[global release];
}
- (BOOL)textFieldShouldReturn:(UITextField*)aTextField
{
[aTextField resignFirstResponder];
return YES;
}
@end
PSANewGame.h
#import <UIKit/UIKit.h>
@interface PSANewGame : UIViewController
@property (retain, nonatomic) IBOutlet UITextField *player1Name;
@property (retain, nonatomic) IBOutlet UITextField *player2Name;
@property (retain, nonatomic) IBOutlet UITextField *player3Name;
@property (retain, nonatomic) IBOutlet UITextField *player4Name;
@property (retain, nonatomic) IBOutlet UITextField *player5Name;
@property (retain, nonatomic) IBOutlet UITextField *player6Name;
@end
PSACurrentGame.m(下一个观点)
#import "PSACurrentGame.h"
#import "PSAGlobal.h"
@interface PSACurrentGame ()
@property (retain, nonatomic) IBOutlet UILabel *R1P1Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P1Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P1Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P1Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P1Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P1Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP1Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP1Phase;
@property (retain, nonatomic) IBOutlet UILabel *R1P2Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P2Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P2Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P2Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P2Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P2Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP2Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP2Phase;
@property (retain, nonatomic) IBOutlet UILabel *R1P3Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P3Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P3Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P3Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P3Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P3Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP3Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP3Phase;
@property (retain, nonatomic) IBOutlet UILabel *R1P4Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P4Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P4Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P4Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P4Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P4Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP4Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP4Phase;
@property (retain, nonatomic) IBOutlet UILabel *R1P5Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P5Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P5Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P5Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P5Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P5Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP5Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP5Phase;
@property (retain, nonatomic) IBOutlet UILabel *R1P6Score;
@property (retain, nonatomic) IBOutlet UILabel *R1P6Phase;
@property (retain, nonatomic) IBOutlet UILabel *R2P6Score;
@property (retain, nonatomic) IBOutlet UILabel *R2P6Phase;
@property (retain, nonatomic) IBOutlet UILabel *R3P6Score;
@property (retain, nonatomic) IBOutlet UILabel *R3P6Phase;
@property (retain, nonatomic) IBOutlet UILabel *ToP6Score;
@property (retain, nonatomic) IBOutlet UILabel *ToP6Phase;
@property (retain, nonatomic) IBOutlet UILabel *player1;
@property (retain, nonatomic) IBOutlet UILabel *player2;
@property (retain, nonatomic) IBOutlet UILabel *player3;
@property (retain, nonatomic) IBOutlet UILabel *player4;
@property (retain, nonatomic) IBOutlet UILabel *player5;
@property (retain, nonatomic) IBOutlet UILabel *player6;
@property (retain, nonatomic) IBOutlet UILabel *R1List2;
@property (retain, nonatomic) IBOutlet UILabel *R2List2;
@property (retain, nonatomic) IBOutlet UILabel *R3List2;
@property (retain, nonatomic) IBOutlet UILabel *ToList2;
@end
@implementation PSACurrentGame
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
PSAGlobal *global = [PSAGlobal getInstance];
self.player1.text = global.player1Name;
self.player2.text = global.player2Name;
self.player3.text = global.player3Name;
self.player4.text = global.player4Name;
self.player5.text = global.player5Name;
self.player6.text = global.player6Name;
if ([self.player3.text isEqual: @""]) {
self.player3.hidden = YES;
self.R1P3Phase.hidden = YES;
self.R1P3Score.hidden=YES;
self.R2P3Phase.hidden = YES;
self.R2P3Score.hidden=YES;
self.R3P3Phase.hidden = YES;
self.R3P3Score.hidden=YES;
self.ToP3Phase.hidden = YES;
self.ToP3Score.hidden=YES;
}
if ([self.player4.text isEqual: @""]) {
self.player4.hidden = YES;
self.R1P4Phase.hidden = YES;
self.R1P4Score.hidden=YES;
self.R2P4Phase.hidden = YES;
self.R2P4Score.hidden=YES;
self.R3P4Phase.hidden = YES;
self.R3P4Score.hidden=YES;
self.ToP4Phase.hidden = YES;
self.ToP4Score.hidden=YES;
}
if ([self.player5.text isEqual: @""]) {
self.player5.hidden = YES;
self.R1P5Phase.hidden = YES;
self.R1P5Score.hidden=YES;
self.R2P5Phase.hidden = YES;
self.R2P5Score.hidden=YES;
self.R3P5Phase.hidden = YES;
self.R3P5Score.hidden=YES;
self.ToP5Phase.hidden = YES;
self.ToP5Score.hidden=YES;
}
if ([self.player6.text isEqual: @""]) {
self.player6.hidden = YES;
self.R1P6Phase.hidden = YES;
self.R1P6Score.hidden=YES;
self.R2P6Phase.hidden = YES;
self.R2P6Score.hidden=YES;
self.R3P6Phase.hidden = YES;
self.R3P6Score.hidden=YES;
self.ToP6Phase.hidden = YES;
self.ToP6Score.hidden=YES;
}
if ([self.player4.text isEqual: @""] && [self.player5.text isEqual:@""] && [self.player6.text isEqual:@""]) {
self.R1List2.hidden = YES;
self.R2List2.hidden = YES;
self.R3List2.hidden = YES;
self.ToList2.hidden = YES;
}
[global release];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[_R1P1Score release];
[_R1P1Phase release];
[_R2P1Score release];
[_R2P1Phase release];
[_R3P1Score release];
[_R1P1Score release];
[_R1P1Phase release];
[_R2P1Score release];
[_R2P1Phase release];
[_R3P1Score release];
[_R3P1Phase release];
[_ToP1Score release];
[_ToP1Phase release];
[_R1P2Score release];
[_R1P2Phase release];
[_R2P2Score release];
[_R2P2Phase release];
[_R3P2Score release];
[_R3P2Phase release];
[_ToP2Score release];
[_ToP2Phase release];
[_R1P3Score release];
[_R1P3Phase release];
[_R2P3Score release];
[_R2P3Phase release];
[_R3P3Score release];
[_R3P3Phase release];
[_ToP3Score release];
[_ToP3Phase release];
[_R1P4Score release];
[_R1P4Phase release];
[_R2P4Score release];
[_R2P4Phase release];
[_R3P4Score release];
[_R3P4Phase release];
[_ToP4Score release];
[_ToP4Phase release];
[_R1P5Score release];
[_R1P5Phase release];
[_R2P5Score release];
[_R2P5Phase release];
[_R3P5Score release];
[_R3P5Phase release];
[_ToP5Score release];
[_ToP5Phase release];
[_R1P6Score release];
[_R1P6Phase release];
[_R2P6Score release];
[_R2P6Phase release];
[_R3P6Score release];
[_R3P6Phase release];
[_ToP6Score release];
[_ToP6Phase release];
[_player1 release];
[_player2 release];
[_player3 release];
[_player4 release];
[_player5 release];
[_player6 release];
[_R1List2 release];
[_R2List2 release];
[_R3List2 release];
[_ToList2 release];
[super dealloc];
}
- (void) updateScoresPlayer1Score:(int)player1Score player2Score:(int)player2Score player3Score:(int)player3Score player4Score:(int)player4Score player5Score:(int)player5Score player6Score:(int)player6Score {
//Move info up from each player's score to the history rounds.
// Round 2 -> Round 3
self.R3P1Score.text = self.R2P1Score.text;
self.R3P1Phase.text = self.R2P1Phase.text;
self.R3P2Score.text = self.R2P2Score.text;
self.R3P2Phase.text = self.R2P2Phase.text;
self.R3P3Score.text = self.R2P3Score.text;
self.R3P3Phase.text = self.R2P3Phase.text;
self.R3P4Score.text = self.R2P4Score.text;
self.R3P4Phase.text = self.R2P4Phase.text;
self.R3P5Score.text = self.R2P5Score.text;
self.R3P5Phase.text = self.R2P5Phase.text;
self.R3P6Score.text = self.R2P6Score.text;
self.R3P6Phase.text = self.R2P6Phase.text;
//Round 1 -> Round 2
self.R2P1Score.text = self.R1P1Score.text;
self.R2P1Phase.text = self.R1P1Phase.text;
self.R2P2Score.text = self.R1P2Score.text;
self.R2P2Phase.text = self.R1P2Phase.text;
self.R2P3Score.text = self.R1P3Score.text;
self.R2P3Phase.text = self.R1P3Phase.text;
self.R2P4Score.text = self.R1P4Score.text;
self.R2P4Phase.text = self.R1P4Phase.text;
self.R2P5Score.text = self.R1P5Score.text;
self.R2P5Phase.text = self.R1P5Phase.text;
self.R2P6Score.text = self.R1P6Score.text;
self.R2P6Phase.text = self.R1P6Phase.text;
//Total -> Round 1
self.R1P1Score.text = self.ToP1Score.text;
self.R1P1Phase.text = self.ToP1Phase.text;
self.R1P2Score.text = self.ToP2Score.text;
self.R1P2Phase.text = self.ToP2Phase.text;
self.R1P3Score.text = self.ToP3Score.text;
self.R1P3Phase.text = self.ToP3Phase.text;
self.R1P4Score.text = self.ToP4Score.text;
self.R1P4Phase.text = self.ToP4Phase.text;
self.R1P5Score.text = self.ToP5Score.text;
self.R1P5Phase.text = self.ToP5Phase.text;
self.R1P6Score.text = self.ToP6Score.text;
self.R1P6Phase.text = self.ToP6Phase.text;
//Setting Total's score
//Setting Player 1's Score
int P1CurScore = [self.ToP1Score.text integerValue];
int P1CurPhase = [self.ToP1Phase.text integerValue];
self.ToP1Score.text = [NSString stringWithFormat:@"%d", (P1CurScore + player1Score)];
if (player1Score < 50) {
self.ToP1Phase.text = [NSString stringWithFormat:@"%d", (P1CurPhase + 1)];
}
//Setting Player 2's Score
int P2CurScore = [self.ToP2Score.text integerValue];
int P2CurPhase = [self.ToP2Phase.text integerValue];
self.ToP2Score.text = [NSString stringWithFormat:@"%d", (P2CurScore + player2Score)];
if (player2Score < 50) {
self.ToP2Phase.text = [NSString stringWithFormat:@"%d", (P2CurPhase + 1)];
}
//Setting Player 3's Score
int P3CurScore = [self.ToP3Score.text integerValue];
int P3CurPhase = [self.ToP3Phase.text integerValue];
self.ToP3Score.text = [NSString stringWithFormat:@"%d", (P3CurScore + player3Score)];
if (player3Score < 50) {
self.ToP3Phase.text = [NSString stringWithFormat:@"%d", (P3CurPhase + 1)];
}
//Setting Player 4's Score
int P4CurScore = [self.ToP4Score.text integerValue];
int P4CurPhase = [self.ToP4Phase.text integerValue];
self.ToP4Score.text = [NSString stringWithFormat:@"%d", (P4CurScore + player4Score)];
if (player4Score < 50) {
self.ToP1Phase.text = [NSString stringWithFormat:@"%d", (P4CurPhase + 1)];
}
//Setting Player 5's Score
int P5CurScore = [self.ToP5Score.text integerValue];
int P5CurPhase = [self.ToP5Phase.text integerValue];
self.ToP5Score.text = [NSString stringWithFormat:@"%d", (P5CurScore + player5Score)];
if (player5Score < 50) {
self.ToP5Phase.text = [NSString stringWithFormat:@"%d", (P5CurPhase + 1)];
}
//Setting Player 6's Score
int P6CurScore = [self.ToP6Score.text integerValue];
int P6CurPhase = [self.ToP6Phase.text integerValue];
self.ToP6Score.text = [NSString stringWithFormat:@"%d", (P6CurScore + player6Score)];
if (player6Score < 50) {
self.ToP6Phase.text = [NSString stringWithFormat:@"%d", (P6CurPhase + 1)];
}
}
@end
PSACurrentGame.h
#import <UIKit/UIKit.h>
@interface PSACurrentGame : UIViewController
- (void) updateScoresPlayer1Score:(int)player1Score player2Score:(int)player2Score player3Score:(int)player3Score player4Score:(int)player4Score player5Score:(int)player5Score player6Score:(int)player6Score;
@end
最后调试期间“All Output”框中的代码。
2013-09-01 09:07:49.679 Phase 10 Scoring Application[73300:11303] -[UINibStorage player1Name]: unrecognized selector sent to instance 0x71e10b0
2013-09-01 09:07:49.686 Phase 10 Scoring Application[73300:11303] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UINibStorage player1Name]: unrecognized selector sent to instance 0x71e10b0'
*** First throw call stack:
(0x1ca3012 0x10e0e7e 0x1d2e4bd 0x1c92bbc 0x1c9294e 0x339b 0x1061c7 0x106232 0x111c25 0x3113a3 0x10eee3 0x10f167 0x10f1a7 0x47b0a2 0x46cb99 0x46cc14 0x10f4705 0x282c0 0x28258 0xe9021 0xe957f 0xe86e8 0x57cef 0x57f02 0x35d4a 0x27698 0x1bfedf9 0x1bfead0 0x1c18bf5 0x1c18962 0x1c49bb6 0x1c48f44 0x1c48e1b 0x1bfd7e3 0x1bfd668 0x24ffc 0x2822 0x2755)
libc++abi.dylib: terminate called throwing an exception
PSAGlobal.m
#import "PSAGlobal.h"
@implementation PSAGlobal
static PSAGlobal *instance =nil;
+(PSAGlobal *)getInstance
{
@synchronized(self)
{
if(instance==nil)
{
instance= [PSAGlobal new];
}
}
return instance;
}
@end
PSAGlobal.h
#import <Foundation/Foundation.h>
@interface PSAGlobal : NSObject
@property(nonatomic,retain)NSString *player1Name;
@property(nonatomic,retain)NSString *player2Name;
@property(nonatomic,retain)NSString *player3Name;
@property(nonatomic,retain)NSString *player4Name;
@property(nonatomic,retain)NSString *player5Name;
@property(nonatomic,retain)NSString *player6Name;
+ (PSAGlobal *)getInstance;
@end
知道为什么会这样吗?
答案 0 :(得分:1)
这可能是内存管理问题。考虑切换到ARC,这将自动(大部分)所有这些东西。