Thread 1: SIGBART, Again - iphone

I know this question has been asked before, but I can't figure out why it is happening. There seem to be a lot of reasons why this could happen.
It happens when I click a button (called next) on one of my views. I'll give you the code for the view and the view following it. This is not a game app, despite the name of some of the views.
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 (the next view)
#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
And finally the code in the "All Output" box during debug.
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
Any idea why this is happening?

It's probably a memory management issue. Consider switching over to ARC, which will automate (most of) all that stuff.

Related

strange error 'unrecognized selector sent to instance'

I'm having an error when trying to pass a bunch of variables from one class to another, my first class controls one view, and my other class is a tableviewcontroller that controls a table view, I have a segue named "shoplistSegue" and when I click one button it performs the segue and pass variables using "prepareForSegue" method. but when I click the button it freezes and an error appears "unrecognized selector sent to instance 0x74af950".
class1.h
#interface CalcularViewController : UIViewController{
int calcularIntHomens;
int calcularIntMulheres;
int calcularIntCriancas;
}
#property (strong, nonatomic) IBOutlet UILabel *calcularLabelHomens;
#property (strong, nonatomic) IBOutlet UILabel *calcularLabelMulheres;
#property (strong, nonatomic) IBOutlet UILabel *calcularLabelCriancas;
#property (strong, nonatomic) IBOutlet UILabel *calcularLabelFantasmas;
#property int calcularIntHomens;
#property int calcularIntMulheres;
#property int calcularIntCriancas;
- (IBAction)subtractHomens:(id)sender;
- (IBAction)subtractMulheres:(id)sender;
- (IBAction)subtractCriancas:(id)sender;
- (IBAction)addHomens:(id)sender;
- (IBAction)addMulheres:(id)sender;
- (IBAction)addCriancas:(id)sender;
- (IBAction)showResultsIfNotNull:(id)sender;
#end
class1.m
#import "CalcularViewController.h"
#import "ResultadoViewController.h"
#interface CalcularViewController ()
#end
#implementation CalcularViewController
#synthesize calcularIntCriancas, calcularIntHomens, calcularIntMulheres, calcularLabelCriancas, calcularLabelHomens, calcularLabelMulheres, calcularLabelFantasmas;
- (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.
}
- (IBAction)subtractHomens:(id)sender {
if (calcularIntHomens > 0) {
calcularIntHomens = calcularIntHomens -1;
NSString *submen = [[NSString alloc] initWithFormat:#"%i", calcularIntHomens];
calcularLabelHomens.text = submen;
}
}
- (IBAction)subtractMulheres:(id)sender{
if (calcularIntMulheres > 0) {
calcularIntMulheres = calcularIntMulheres -1;
NSString *subwoman = [[NSString alloc] initWithFormat:#"%i", calcularIntMulheres];
calcularLabelMulheres.text = subwoman;
}
}
- (IBAction)subtractCriancas:(id)sender{
if (calcularIntCriancas > 0) {
calcularIntCriancas = calcularIntCriancas -1;
NSString *subchild = [[NSString alloc] initWithFormat:#"%i", calcularIntCriancas];
calcularLabelCriancas.text = subchild;
}
}
- (IBAction)addCriancas:(id)sender{
calcularIntCriancas = calcularIntCriancas +1;
NSString *addchild = [[NSString alloc] initWithFormat:#"%i", calcularIntCriancas];
calcularLabelCriancas.text = addchild;
}
- (IBAction)addHomens:(id)sender{
calcularIntHomens = calcularIntHomens +1;
NSString *addmen = [[NSString alloc] initWithFormat:#"%i", calcularIntHomens];
calcularLabelHomens.text = addmen;
}
- (IBAction)addMulheres:(id)sender{
calcularIntMulheres = calcularIntMulheres +1;
NSString *addwoman = [[NSString alloc] initWithFormat:#"%i", calcularIntMulheres];
calcularLabelMulheres.text = addwoman;
}
-(IBAction)showResultsIfNotNull:(id)sender{
if (calcularIntHomens == 0) {
if (calcularIntMulheres == 0) {
if (calcularIntCriancas == 0) {
calcularLabelFantasmas.text = #"Você vai fazer um churrasco pra fantasmas?";
} else {
[self performSegueWithIdentifier:#"resultadoSegue" sender:self];
}
} else {
[self performSegueWithIdentifier:#"resultadoSegue" sender:self];
}
} else {
[self performSegueWithIdentifier:#"resultadoSegue" sender:self];
}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"resultadoSegue"]) {
ResultadoViewController *resultados = [segue destinationViewController];
resultados.resultadoIntCriancas = calcularIntCriancas;
resultados.resultadoIntHomens = calcularIntHomens;
resultados.resultadoIntMulheres = calcularIntMulheres;
}
}
#end
class2.h
#import <UIKit/UIKit.h>
#interface ResultadoViewController : UIViewController{
int resultadoIntHomens;
int resultadoIntMulheres;
int resultadoIntCriancas;
IBOutlet UIScrollView *scroller;
float resultadoGado;
float resultadoFrango;
float resultadoPorco;
float resultadoLinguica;
float resultadoQueijo;
float resultadoPaodealho;
float resultadoAcompanhamento;
float resultadoAbacaxiassado;
float resultadoCebolaassada;
float resultadoBebidas;
float resultadoAlcool;
int areThereBebidas;
BOOL picanhaBOOL;
BOOL alcatraBOOL;
BOOL maminhaBOOL;
BOOL contrafileBOOL;
BOOL lombinhoBOOL;
BOOL linguicaBOOL;
BOOL coracaoBOOL;
BOOL asaBOOL;
BOOL coxaBOOL;
BOOL queijoBOOL;
BOOL paodealhoBOOL;
BOOL arrozBOOL;
BOOL farofaBOOL;
BOOL vinagreteBOOL;
BOOL maionesesaladaBOOL;
BOOL saladaBOOL;
BOOL abacaxiassadoBOOL;
BOOL cebolaBOOL;
BOOL cervejaBOOL;
BOOL refriBOOL;
BOOL aguaBOOL;
BOOL vodkaBOOL;
BOOL sucoBOOL;
int gadoTotal;
int frangoTotal;
int acompanhamentoTotal;
int bebidaTotal;
int something;
int alcoolTotal;
}
#property int alcoolTotal;
#property int areThereBebidas;
#property float resultadoAlcool;
#property int resultadoIntHomens;
#property int resultadoIntMulheres;
#property int resultadoIntCriancas;
#property float resultadoGado;
#property float resultadoFrango;
#property float resultadoPorco;
#property float resultadoLinguica;
#property float resultadoQueijo;
#property float resultadoPaodealho;
#property float resultadoAcompanhamento;
#property float resultadoAbacaxiassado;
#property float resultadoCebolaassada;
#property float resultadoBebidas;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelPicanha;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAlcatra;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelMaminha;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelContrafile;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelLombinho;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelLinguica;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCoracao;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAsa;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCoxa;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelQueijo;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelPaodealho;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelArroz;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelFarofa;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelVinagrete;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSaladamaionese;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSalada;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAbacaxiassado;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCebola;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelCerveja;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelRefri;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelAgua;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelVodka;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelSuco;
#property (strong, nonatomic) IBOutlet UILabel *resultadoLabelFome;
- (IBAction)addPicanha:(id)sender;
- (IBAction)addAlcatra:(id)sender;
- (IBAction)addMaminha:(id)sender;
- (IBAction)addContrafile:(id)sender;
- (IBAction)addLombinho:(id)sender;
- (IBAction)addLinguica:(id)sender;
- (IBAction)addCoracao:(id)sender;
- (IBAction)addAsa:(id)sender;
- (IBAction)addCoxa:(id)sender;
- (IBAction)addQueijo:(id)sender;
- (IBAction)addPaodealho:(id)sender;
- (IBAction)addArroz:(id)sender;
- (IBAction)addFarofa:(id)sender;
- (IBAction)addVinagrete:(id)sender;
- (IBAction)addSaladamaionese:(id)sender;
- (IBAction)addSalada:(id)sender;
- (IBAction)addAbacaxi:(id)sender;
- (IBAction)AddCebola:(id)sender;
- (IBAction)addCerveja:(id)sender;
- (IBAction)addRefri:(id)sender;
- (IBAction)addAgua:(id)sender;
- (IBAction)addVodka:(id)sender;
- (IBAction)addSuco:(id)sender;
- (IBAction)buttonBack:(id)sender;
- (IBAction)buttonNext:(id)sender;
#property BOOL picanhaBOOL;
#property BOOL alcatraBOOL;
#property BOOL maminhaBOOL;
#property BOOL contrafileBOOL;
#property BOOL lombinhoBOOL;
#property BOOL linguicaBOOL;
#property BOOL coracaoBOOL;
#property BOOL asaBOOL;
#property BOOL coxaBOOL;
#property BOOL queijoBOOL;
#property BOOL paodealhoBOOL;
#property BOOL arrozBOOL;
#property BOOL farofaBOOL;
#property BOOL vinagreteBOOL;
#property BOOL maionesesaladaBOOL;
#property BOOL saladaBOOL;
#property BOOL abacaxiassadoBOOL;
#property BOOL cebolaBOOL;
#property BOOL cervejaBOOL;
#property BOOL refriBOOL;
#property BOOL aguaBOOL;
#property BOOL vodkaBOOL;
#property BOOL sucoBOOL;
#property int gadoTotal;
#property int frangoTotal;
#property int acompanhamentoTotal;
#property int bebidaTotal;
#property int something;
#end
class2.m
#import "ResultadoViewController.h"
#import "ShoplistViewController.h"
#interface ResultadoViewController ()
#end
#implementation ResultadoViewController
#synthesize resultadoIntCriancas, resultadoIntHomens, resultadoIntMulheres, resultadoAbacaxiassado, resultadoAcompanhamento, resultadoBebidas, resultadoCebolaassada, resultadoFrango, resultadoGado, resultadoLinguica, resultadoPaodealho, resultadoPorco, resultadoQueijo, resultadoLabelAbacaxiassado, resultadoLabelAgua, resultadoLabelAlcatra, resultadoLabelArroz, resultadoLabelAsa, resultadoLabelCebola, resultadoLabelCerveja, resultadoLabelContrafile, resultadoLabelCoracao, resultadoLabelCoxa, resultadoLabelFarofa, resultadoLabelFome, resultadoLabelLinguica, resultadoLabelLombinho, resultadoLabelMaminha, resultadoLabelPaodealho, resultadoLabelPicanha, resultadoLabelQueijo, resultadoLabelRefri, resultadoLabelSalada, resultadoLabelSaladamaionese, resultadoLabelSuco, resultadoLabelVinagrete, resultadoLabelVodka, picanhaBOOL, alcatraBOOL, lombinhoBOOL, contrafileBOOL, maminhaBOOL, linguicaBOOL, coracaoBOOL, queijoBOOL, asaBOOL, coxaBOOL, paodealhoBOOL, arrozBOOL, farofaBOOL, vinagreteBOOL, saladaBOOL, maionesesaladaBOOL, abacaxiassadoBOOL, cebolaBOOL, cervejaBOOL, refriBOOL, aguaBOOL, sucoBOOL, vodkaBOOL, gadoTotal, something, frangoTotal, acompanhamentoTotal, bebidaTotal, resultadoAlcool, areThereBebidas, alcoolTotal;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(void)viewDidAppear:(BOOL)animated{
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320, 1035)];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
backButton.frame = CGRectMake(20, 986, 108, 30);
[backButton setTitle:#"Voltar" forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(buttonBack:) forControlEvents:UIControlEventTouchUpInside];
[scroller addSubview:backButton];
UIButton *nextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
nextButton.frame = CGRectMake(192, 986, 108, 30);
[nextButton setTitle:#"Continuar..." forState:UIControlStateNormal];
[nextButton addTarget:self action:#selector(buttonNext:) forControlEvents:UIControlEventTouchUpInside];
[scroller addSubview:nextButton];
}
- (void)viewDidLoad
{
gadoTotal = 0;
something = 0;
resultadoGado = resultadoIntHomens * 0.400 + resultadoIntMulheres * 0.355 + resultadoIntCriancas * 0.200;
resultadoLinguica = resultadoIntHomens * 0.070 + resultadoIntMulheres * 0.050 + resultadoIntCriancas * 0.030;
resultadoPorco = resultadoIntHomens * 0.060 + resultadoIntMulheres * 0.035 + resultadoIntCriancas * 0.030;
resultadoFrango = resultadoIntHomens * 0.085 + resultadoIntMulheres * 0.055 + resultadoIntCriancas * 0.042;
resultadoQueijo = resultadoIntHomens * 0.050 + resultadoIntMulheres * 0.040 + resultadoIntCriancas * 0.020;
resultadoAcompanhamento = resultadoIntHomens * 0.225 + resultadoIntMulheres * 0.190 + resultadoIntCriancas * 0.100;
resultadoAbacaxiassado = resultadoIntHomens * 0.040 + resultadoIntMulheres * 0.025 + resultadoIntCriancas * 0.020;
resultadoCebolaassada = resultadoIntHomens * 0.050 + resultadoIntMulheres * 0.035 + resultadoIntCriancas * 0.020;
resultadoPaodealho = resultadoIntHomens * 0.070 + resultadoIntMulheres * 0.045 + resultadoIntCriancas * 0.030;
resultadoAlcool = resultadoIntHomens * 0.600 + resultadoIntMulheres * 0.350 + resultadoIntCriancas * 0.000;
resultadoBebidas = resultadoIntHomens * 0.500 + resultadoIntMulheres * 0.650 + resultadoIntCriancas * 0.700;
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)buttonBack:(id)sender{
[self performSegueWithIdentifier:#"backtoCalcSegue" sender:self];
}
-(IBAction)buttonNext:(id)sender{
if (gadoTotal > 0){
[self performSegueWithIdentifier:#"shoplistSegue" sender:self];
}else { resultadoLabelFome.text = #"Assim as pessoas vão morrer de fome!";}
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"shoplistSegue"]) {
ShoplistViewController *resultados = [segue destinationViewController];
resultados.shoplistPicanha = [resultadoLabelPicanha.text floatValue];
resultados.shoplistAlcatra = [resultadoLabelAlcatra.text floatValue];
resultados.shoplistMaminha = [resultadoLabelMaminha.text floatValue];
resultados.shoplistContrafile = [resultadoLabelContrafile.text floatValue];
resultados.shoplistLombinho = [resultadoLabelLombinho.text floatValue];
resultados.shoplistLinguica = [resultadoLabelLinguica.text floatValue];
resultados.shoplistAsa = [resultadoLabelAsa.text floatValue];
resultados.shoplistCoxa = [resultadoLabelCoxa.text floatValue];
resultados.shoplistCoracao = [resultadoLabelCoracao.text floatValue];
resultados.shoplistQueijo = [resultadoLabelQueijo.text floatValue];
resultados.shoplistPaodealho = [resultadoLabelPaodealho.text floatValue];
resultados.shoplistArroz = [resultadoLabelArroz.text floatValue];
resultados.shoplistFarofa = [resultadoLabelFarofa.text floatValue];
resultados.shoplistVinagrete = [resultadoLabelVinagrete.text floatValue];
resultados.shoplistMaionese = [resultadoLabelSaladamaionese.text floatValue];
resultados.shoplistSalada = [resultadoLabelSalada.text floatValue];
resultados.shoplistAbacaxi = [resultadoLabelAbacaxiassado.text floatValue];
resultados.shoplistCebola = [resultadoLabelCebola.text floatValue];
resultados.shoplistAgua = [resultadoLabelAgua.text floatValue];
resultados.shoplistCerveja = [resultadoLabelCerveja.text floatValue];
resultados.shoplistRefri = [resultadoLabelRefri.text floatValue];
resultados.shoplistVodka = [resultadoLabelVodka.text floatValue];
resultados.shoplistSuco = [resultadoLabelSuco.text floatValue];
}
}
#end
EDIT:
it was working properly until i deleted the destination view and put it there again cause it had a little problem on interface builder. When I put it there, on the inspector i put the controlling class againg and everything it had before again...
This is the problem:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"shoplistSegue"]) {
ShoplistViewController *resultados = [segue destinationViewController];
resultados.shoplistPicanha = [resultadoLabelPicanha.text floatValue];
Either ShoplistViewController doesn't implement -setShoplistPicanha: / has no #property (readwrite) shopListPicanha
or your [segue destinationViewController] doesn't return what you think it does (ie not
a ShoplistViewController).
You try to call
UITableViewController setShoplistPicanha:
and apparently it is not defined (with one argument)

Moving UITextField that is located under keyboard

so like im sure every iOS programmer i ran into a problem, when trying to have a page full of UITextFields, it became evident that when the keyboard comes up it covers half of them. So i went to Apple's documentation and read all about it and wrote up the code for it, but it isn't working for me. Every time i run the view it crashes. Thanks in advance for your help.
.h file
#interface NewUserViewController : UIViewController{
}
- (IBAction)signMeUpButtonPressed:(id)sender;
#property (weak, nonatomic) IBOutlet UITextField *activeField;
#property (weak, nonatomic) IBOutlet UIScrollView *contentScrollView;
#property (weak, nonatomic) IBOutlet UIButton *backButton;
#property (weak, nonatomic) IBOutlet UILabel *firstNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *firstNameInput;
#property (weak, nonatomic) IBOutlet UILabel *lastNameLabel;
#property (weak, nonatomic) IBOutlet UITextField *lastNameInput;
#property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
#property (weak, nonatomic) IBOutlet UITextField *usernameInput;
#property (weak, nonatomic) IBOutlet UILabel *emailLabel;
#property (weak, nonatomic) IBOutlet UITextField *emailInput;
#property (weak, nonatomic) IBOutlet UILabel *passwordLabel;
#property (weak, nonatomic) IBOutlet UITextField *setPasswordInput;
#property (weak, nonatomic) IBOutlet UILabel *reenterPasswordLabel;
#property (weak, nonatomic) IBOutlet UITextField *checkSetPasswordInput;
#property (weak, nonatomic) IBOutlet UIButton *signMeUpButton;
All are connected to their outlets (except for active field. Im not sure where it belongs or what it should be connected to)
.m file
#implementation NewUserViewController
#synthesize contentScrollView;
#synthesize activeField;
#synthesize firstNameLabel, lastNameLabel, usernameLabel, emailLabel, passwordLabel, reenterPasswordLabel;
#synthesize firstNameInput, lastNameInput, usernameInput, emailInput, setPasswordInput, checkSetPasswordInput;
#synthesize backButton, signMeUpButton;
- (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)textFieldDidBeginEditing:(UITextField *)textField
{
activeField = textField;
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
activeField = nil;
}
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
contentScrollView.contentInset = contentInsets;
contentScrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
[contentScrollView setContentOffset:scrollPoint animated:YES];
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
contentScrollView.contentInset = contentInsets;
contentScrollView.scrollIndicatorInsets = contentInsets;
}
- (IBAction)signMeUpButtonPressed:(id)sender {
}
Try this:
- (void)keyboardWasShown:(NSNotification *)notification {
NSDictionary* userInfo = [notification userInfo];
CGRect keyboardEndFrame;
[[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] getValue:&keyboardEndFrame];
//offset is global
offset = contentScrollView.contentOffset;
CGRect viewFrame = contentScrollView.frame;
CGRect keyboardFrame = [self convertRect:keyboardEndFrame toView:nil];
viewFrame.size.height -= keyboardFrame.size.height;
contentScrollView.frame = viewFrame;
UITextField *current = (UITextField *)[self findFirstResponder];
CGRect textFieldRect = current.frame;
[contentScrollView scrollRectToVisible:textFieldRect animated:YES];
}
- (UIView *)findFirstResponder {
for (UIView *subView in scrollView.subviews) {
if ([subView isFirstResponder]){
return subView;
}
}
return nil;
}
- (void) keyboardWillBeHidden:(NSNotification *)notification {
//scrollViewFrame is global the first frame of you scrollview
contentScrollView.frame = scrollViewFrame;
contentScrollView.contentOffset =offset;
}
this is not a complete code this is just a little logic of performing what you want to do.

initWithCoder doesn't set UILabel property (UIFont and text color)

I have the following code for my UICollectionViewCell
#property (strong, nonatomic) IBOutlet UIImageView *storyImage;
#property (strong, nonatomic) IBOutlet UILabel *titleLabel;
#property (strong, nonatomic) IBOutlet UILabel *descriptionLabel;
#end
#implementation Story
#synthesize storyImage;
#synthesize titleLabel;
#synthesize descriptionLabel;
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self)
{
[self.contentView addSubview:self.titleLabel];
[self.contentView addSubview:self.descriptionLabel];
[self.contentView addSubview:self.storyImage];
[self.titleLabel setFont:[UIFont fontWithName:kProximaNovaBold size:15]];
[self.descriptionLabel setFont:[UIFont fontWithName:kProximaNova size:13]];
[self.descriptionLabel setTextColor:[UIColor colorWithWhite:140/255.f alpha:1.0]];
self.descriptionLabel.frame = CGRectIntegral(self.descriptionLabel.frame);
self.descriptionLabel.center = roundedCenterPoint(self.descriptionLabel.center);
}
return self;
}
but for some reason it's not setting up the property. I'd have to move it out of the init method and put it inside a separate method and call this after calling:
dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath
and then it would work. Any idea why?
You want to be doing this stuff in awakeFromNib: when everything from the nib has actually been loaded and connected
From the docs for NSObject UIKit Additions
Discussion
The nib-loading infrastructure sends an awakeFromNib message to each object recreated from a nib archive, but only after all the objects in the archive have been loaded and initialized.

Gesture recogniser star rating system

I used this star rating system at https://github.com/dlinsin/DLStarRating the gesture is working fine however it dosen't seem to be using the delegate correctly and therefore when I select a star the rating is not refreshing. Here is my code:
.main File
- (void)viewDidLoad
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//check if value has been previously saved
if( ![defaults stringForKey:#"username"] ) {
CustomerLogin *customerlogin = [[CustomerLogin alloc]
initWithNibName:#"CustomerLogin" bundle:nil];
[self presentModalViewController:customerlogin animated:YES];
// customerlogin.view.frame = CGRectMake(0, 0, 700, 900);
// customerlogin.view.center = CGPointMake( 768/2, 1024/2);
//[self.navigationController pushViewController:customerlogin animated:YES];
[customerlogin release];
}
UIBarButtonItem * sortButton = [[UIBarButtonItem alloc] initWithTitle:#"Submit" style:UIBarButtonItemStyleBordered target:self action:#selector(Submit)];
self.navigationItem.rightBarButtonItem = sortButton;
[sortButton release];
rating.delegate = self;
comments.delegate = self;
bestnight.delegate = self;
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"background_texture.png"]];
self.view.backgroundColor = background;
[background release];
self.title = #"Write Review";
[super viewDidLoad];
//Star touch
DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0,0, 320, 100) andStars:5];
customNumberOfStars.backgroundColor = [UIColor clearColor];
customNumberOfStars.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
customNumberOfStars.rating = 3;
[self.view addSubview:customNumberOfStars];
[customNumberOfStars release];
}
-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating
{
self.rating.text = [NSString stringWithFormat:#"%d star rating",rating];
}
.header file
#import "DLStarRatingControl.h"
#class Customer;
#class Place;
#interface CreateReview : UIViewController <UITextFieldDelegate,UITextViewDelegate,DLStarRatingDelegate>
{
Customer*customer;
Place*place;
IBOutlet UITextField * bestnight;
IBOutlet UITextView * comments;
IBOutlet UITextField * rating;
IBOutlet UILabel * testValueLabel;
NSString * identifier;
NSString * password;
NSString * username;
}
#property (nonatomic, retain) IBOutlet UITextField * bestnight;
#property (nonatomic, retain) IBOutlet UITextView * comments;
#property (nonatomic, retain) IBOutlet UITextField * rating;
#property (nonatomic, retain) Customer*customer;
#property (nonatomic, retain) Place*place;
#property (nonatomic, retain) IBOutlet UILabel * testValueLabel;
#property (nonatomic, retain) NSString * identifier;
#property (nonatomic, retain) NSString * password;
#property (nonatomic, retain) NSString * username;
-(id)initWithPlace:(Place*)p;
-(void)newRating:(DLStarRatingControl *)control :(NSUInteger)rating;
#end
It appears you aren't setting the delegate for the DLStarRatingControl:
try adding customNumberOfStars.delegate = self; when setting up your rating control

Can't pass a data object to view controller inside a view controller

I'm not sure why, but I'm having trouble passing a data object (NSManagedObject) to a view controller when that view controller is being instantiated inside another one. When I log the object before it is passed, it has all of its data, but after it gets to the view controller, it is empty. It seems like this should be fairly straight-forward, but for some reason it's just not getting there.
The code which assigns the NSManagedObject to the accepting view controller in the implementation file is: viewController.thisCard = aCard;
Any help is much appreciated. Thanks in advance.
This is the header for the view controller which scrolls:
#interface HandViewController : UIViewController
<UIScrollViewDelegate>
{
IBOutlet UIScrollView *scrollView;
IBOutlet UIPageControl *pageControl;
BOOL pageControlIsChangingPage;
NSManagedObjectContext *context;
}
#property (nonatomic, retain) UIView *scrollView;
#property (nonatomic, retain) UIPageControl *pageControl;
#property (nonatomic, retain) NSManagedObjectContext *context;
/* for pageControl */
- (IBAction)changePage:(id)sender;
#end
this is the viewDidLoad in the implementation of that object
- (void)viewDidLoad
{
scrollView.delegate = self;
[self.scrollView setBackgroundColor:[UIColor blackColor]];
[scrollView setCanCancelContentTouches:NO];
scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scrollView.clipsToBounds = YES;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Game" inManagedObjectContext:[self context]];
[fetchRequest setEntity:entity];
NSError *error;
NSArray *fetchedGames = [self.context executeFetchRequest:fetchRequest error:&error];
[fetchRequest release];
Game *aGame = [fetchedGames objectAtIndex:0];
CGFloat cx = 0;
for (Card *aCard in aGame.turnUpcoming.hand) {
CardViewController *viewController = [[CardViewController alloc] initWithNibName:#"CardViewController" bundle:nil];
CGRect rect = self.view.frame;
rect.size.height = scrollView.frame.size.height - 50;
rect.size.width = scrollView.frame.size.width - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
viewController.view.frame = rect;
viewController.thisCard = aCard;
[scrollView addSubview:viewController.view];
cx += scrollView.frame.size.width;
[viewController release];
}
self.pageControl.numberOfPages = [aGame.turnUpcoming.hand count];
[scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
UPDATE: Per request, I am adding a bit of code from the view controller
This is the header for CardViewController
#interface CardViewController : UIViewController {
UILabel IBOutlet *cardValue;
UILabel IBOutlet *cardInstruction;
UILabel IBOutlet *cardHint;
UILabel IBOutlet *cardTimer;
UIButton IBOutlet *playCardButton;
Card *thisCard;
}
#property (nonatomic, retain) UILabel IBOutlet *cardValue;
#property (nonatomic, retain) UILabel IBOutlet *cardInstruction;
#property (nonatomic, retain) UILabel IBOutlet *cardHint;
#property (nonatomic, retain) UILabel IBOutlet *cardTimer;
#property (nonatomic, retain) UIButton IBOutlet *playCardButton;
#property (nonatomic, retain) Card *thisCard;
#end
Here is the viewDidLoad from the implementation of CardViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if ([thisCard isObjectValid]) {
cardValue.text = [thisCard.value stringValue];
}
}
UPDATE: new code for card loop in viewDidLoad and new CardView code, per suggestions below
loop in viewDidLoad:
for (Card *aCard in aGame.turnUpcoming.hand) {
CGRect rect = scrollView.frame;
rect.size.height = scrollView.frame.size.height - 50;
rect.size.width = scrollView.frame.size.width - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
tempCardView = [[CardView alloc] initWithFrame:rect];
tempCardView.thisCard = aCard;
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"CardView" owner:self options:nil];
tempCardView = [nibObjects objectAtIndex:0];
[scrollView addSubview:tempCardView];
cx += scrollView.frame.size.width;
[tempCardView release];
}
header file CardView.h
#interface CardView : UIView {
UILabel IBOutlet *cardValue;
UILabel IBOutlet *cardInstruction;
UILabel IBOutlet *cardHint;
UILabel IBOutlet *cardTimer;
UIButton IBOutlet *playCardButton;
Card *thisCard;
}
#property (nonatomic, retain) UILabel IBOutlet *cardValue;
#property (nonatomic, retain) UILabel IBOutlet *cardInstruction;
#property (nonatomic, retain) UILabel IBOutlet *cardHint;
#property (nonatomic, retain) UILabel IBOutlet *cardTimer;
#property (nonatomic, retain) UIButton IBOutlet *playCardButton;
#property (nonatomic, retain) Card *thisCard;
#end
implementation file CardView.m
#implementation CardView
#synthesize cardHint;
#synthesize cardTimer;
#synthesize cardValue;
#synthesize cardInstruction;
#synthesize playCardButton;
#synthesize thisCard;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
if ([thisCard isObjectValid]) {
cardValue.text = [thisCard.value stringValue];
cardInstruction.text = thisCard.instruction;
cardHint.text = thisCard.hint;
cardTimer.text = [thisCard.time stringValue];
}
}
return self;
}
#end
UPDATED: 6/16 - Added XIB screen shot
CardView.xib
Seems like your CardViewController should actually be a UIView. As Apple says: " A single view controller typically manages the views associated with a single screen’s worth of content, although in iPad applications this may not always be the case."
(After changes to UIView) in your loop, you're creating one tempCard and then loading another. If you've linked tempCardView in IB (see below), then all you need is:
for (Card *aCard in aGame.turnUpcoming.hand) {
CGRect rect;
rect.size.width = scrollView.frame.size.width - 50;
rect.size.height = scrollView.frame.size.height - 50;
rect.origin.x = ((scrollView.frame.size.width - rect.size.width) / 2) + cx;
rect.origin.y = ((scrollView.frame.size.height - rect.size.height) / 2);
[[NSBundle mainBundle] loadNibNamed:#"CardView" owner:self options:nil]; //magically connected to tempCardView.
self.tempCardView.frame = rect;
self.tempCardView.thisCard = aCard;
[scrollView addSubview:tempCardView];
cx += scrollView.frame.size.width;
self.tempCardView = nil;
}
So, you have two XIBs, your main one that loads with your viewController, and one (CardView) that gets loaded once for each card.
Now, inside CardView, you're trying to set up the labels too soon. During initWithFrame (which in the above case is called by loadFromNib), you don't have access yet to thisCard. You'll need a setter for thisCard, which will be called any time a value is assigned to thisCard property:
-(void) setThisCard: (Card *) newCard {
if (thisCard == newCard) return;
[newCard retain];
[thisCard release];
thisCard = newCard;
self.cardValue.text = [thisCard.value stringValue];
self.cardInstruction.text = thisCard.instruction;
self.cardHint.text = thisCard.hint;
self.cardTimer.text = [thisCard.time stringValue];
}
Now in Interface Builder,
Create CardView.xib with a single UIView with, but set FileOwner to your VC, NOT to CardView because that's who's going to load it (and who has the tempCardView property).
Set the view's type to CardView, then hook it to thetempCardView property of FileOwner (aka HandViewController)
Put all your other card parts inside that CardView and hook them up to that CardView's properties.
You should be all set.