i have a group of textfields and Segmented Control.
i have to get input from a service to all the UIElements, getting correct input for textfields but not the SegmentedControl. Below is my code and ScreenShot attached Please check the image for issue with SegmentedControl TIA
#interface EditBasicProfileViewController ()
#property(nonatomic,strong)NSMutableDictionary *userDict;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) IBOutlet UIView *basicProfileView;
#property (strong, nonatomic) IBOutlet UITextField *txtCellPhone;
#property (strong, nonatomic) IBOutlet UITextField *txtWorkPhone;
#property (strong, nonatomic) IBOutlet UITextField *txtAdress;
#property (strong, nonatomic) IBOutlet UITextField *txtCountry;
#property (strong, nonatomic) IBOutlet UITextField *txtState;
#property (strong, nonatomic) IBOutlet UITextField *txtCity;
#property (strong, nonatomic) IBOutlet UITextField *txtMotherTongue;
#property (strong, nonatomic) IBOutlet UITextField *txtZipcode;
#property (strong, nonatomic) IBOutlet UISegmentedControl *genderSegment;
#property (strong, nonatomic) IBOutlet UISegmentedControl *seekingGenderSegment;
- (IBAction)genderSegmentValueChanged:(id)sender;
- (IBAction)seekingGenderSegmentValueChanged:(id)sender;
- (IBAction)btnCountry:(id)sender;
- (IBAction)btnState:(id)sender;
- (IBAction)btnCity:(id)sender;
- (IBAction)btnMotherTongue:(id)sender;
- (IBAction)btnUpdateClicked:(id)sender;
#property (strong, nonatomic) IBOutlet UIButton *updateButton;
#end
#implementation EditBasicProfileViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[super viewDidLoad];
[self.scrollView addSubview:_basicProfileView];
[_scrollView
setContentSize:self.basicProfileView.frame.size];
gender=#"0";
seekingGender=#"1";
_basicProfileView.backgroundColor=[UIColor clearColor];
NSMutableDictionary *dict=[[NSMutableDictionary alloc] init];
[dict setObject:UserId forKey:#"userId"];
[self ProfileDisplayService:dict];
}
- (IBAction)genderSegmentValueChanged:(id)sender {
if (_genderSegment.selectedSegmentIndex==0)
{
gender=#"0";
}
else
{
gender=#"1";
}
}
- (IBAction)seekingGenderSegmentValueChanged:(id)sender {
if (_seekingGenderSegment.selectedSegmentIndex==0)
{
seekingGender=#"0";
}
else
{
seekingGender=#"1";
}
}
-(void)setupValues
{
gender =[_userDict objectForKey:#"UserGender"];
seekingGender = [_userDict objectForKey:#"SeekingGender"];
_txtCellPhone.text=[_userDict objectForKey:#"UserPhone"];
_txtWorkPhone.text=[_userDict objectForKey:#"UserWorkPhone"];
_txtAdress.text=[_userDict objectForKey:#"UserAddress"];
_txtCountry.text=[_userDict objectForKey:#"UserCountryName"];
_txtState.text=[_userDict objectForKey:#"UserStateName"];
_txtCity.text=[_userDict objectForKey:#"UserCityName"];
_txtMotherTongue.text=[_userDict objectForKey:#"motherTounge"];
_txtZipcode.text=[_userDict objectForKey:#"UserZipCode"];
}
- (IBAction)btnUpdateClicked:(id)sender {
reqType=#"BasicDtls";
[self callEditProfileService:dict];
}
-(void)ProfileDisplayService:(NSMutableDictionary *)dict
{
NSString * post = [[NSString alloc]initWithFormat:#"reqType=BasicDtls&userId=%#",UserId];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"Some Url"]];
RBConnect = [[RBConnection alloc]init];
RBConnect.delegate = self;
[RBConnect postRequestForUrl:url postBody:post];
}
#pragma mark - MRConnection Delegate Methods
- (void)jsonData:(NSDictionary *)jsonDict
{
[SVProgressHUD dismiss];
NSMutableArray *jsonArr;
jsonArr=[jsonDict objectForKey:#"DataTable"];
if (![jsonArr isEqual:[NSNull null]]) {
if ([[jsonArr objectAtIndex:0] objectForKey:#"ABSDetails"]) {
NSMutableDictionary *userDict=[[jsonArr objectAtIndex:0] objectForKey:#"ABSUserDtls"];
gender = [userDict objectForKey:#"UserGender"];
seekingGender = [userDict objectForKey:#"SeekingGender"];
_txtCellPhone.text=[userDict objectForKey:#"UserPhone"];
_txtWorkPhone.text=[userDict objectForKey:#"UserWorkPhone"];
_txtAdress.text=[userDict objectForKey:#"UserAddress"];
_txtCountry.text=[userDict objectForKey:#"UserCountryName"];
_txtState.text=[userDict objectForKey:#"UserStateName"];
_txtCity.text=[userDict objectForKey:#"UserCityName"];
_txtMotherTongue.text=[userDict objectForKey:#"motherTounge"];
_txtZipcode.text=[userDict objectForKey:#"UserZipCode"];
}
}
}
Related
I am unsing the below code in a view controller.. I am fixing the memory issue problem. when I comment out the view did load even it takes a lot of memory above 80 MB what shuold I do to solve it. I changed all variable to strong to weak.
#interface bookNowViewController : UIViewController<GMSMapViewDelegate, UIGestureRecognizerDelegate>
#property (weak, nonatomic) IBOutlet UICollectionView *collectionViewBook;
#property (weak, nonatomic) IBOutlet GMSMapView *mapLoc;
#property (weak, nonatomic) IBOutlet UILabel *distanceLbl;
#property (weak, nonatomic) IBOutlet UILabel *rateLbl;
#property (weak, nonatomic) IBOutlet UICollectionView *collectionViewFacility;
#property (weak, nonatomic) IBOutlet UIView *contentView;
#property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;
#property (weak, nonatomic) IBOutlet UIImageView *animatedImages;//images with fading effect
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *facilityCollectionViewHight;
#property (weak, nonatomic) IBOutlet UILabel *noSportsAvailable;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *facilityLblHightConstant;
#property (weak, nonatomic) IBOutlet UILabel *stName;
#property (weak, nonatomic) IBOutlet UILabel *stAddress;
#property (weak, nonatomic) IBOutlet UIButton *btnI;
#property (weak, nonatomic) IBOutlet UIButton *moreBt;
#property (weak, nonatomic) IBOutlet UIButton *bookNowBt;
#property (weak, nonatomic) IBOutlet UILabel *spRating;
#property (weak, nonatomic) IBOutlet UIView *iNewView;
#property (weak, nonatomic) IBOutlet UILabel *infoLabel;
#property (weak, nonatomic) IBOutlet UILabel *lblIText;
#property (weak, nonatomic) IBOutlet UITextView *textView;
#property (weak, nonatomic) IBOutlet UILabel *confirmationLblText;
and in .m file
#interface bookNowViewController (){
NSMutableArray *savedList, *stadiumAddress, *stadiumLatitude, *stadiumLongitude, *stadiumId, *stadiumImages, *stadiumPrice, *stadiumRating, *stadiumName, *savedImages, *listFacility, *facility, *vendorId, *vendorName, *sportsName;
NSString *post_id2, *postIndex2, *combineData2, *STName;
NSString *raterName, *ratingValue, *raterImage, *comment;
NSInteger myInt;
UIButton *button;
UILabel *navLabel;
NSString *stadium_Id;
NSMutableArray *imageView;// animation images array
UIView *hideView;
UITapGestureRecognizer *oneTap;
NSUInteger jk;
}
#end
and in viewdidload
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self
selector:#selector(swapImage2) userInfo:nil repeats:YES];
[[NSUserDefaults standardUserDefaults] setObject: nil forKey: #"paymentTag"];
self.navigationController.navigationBar.hidden = NO;
stadium_Id = [[NSUserDefaults standardUserDefaults] valueForKey:#"stadium_Id"];
NSLog(#"%#", stadium_Id);
[ProgressHUD showSuccess:#"" Interaction:YES];
NSString *combined2 = stadium_Id;
NSArray* combineData = [[NSArray alloc]init];
combineData = [combined2 componentsSeparatedByString: #" "];
post_id2 = [combineData objectAtIndex:0];
[[NSUserDefaults standardUserDefaults] setObject: post_id2 forKey: #"stadiumid"];
NSLog(#"%#", post_id2);
postIndex2 = [ combineData objectAtIndex:1];
STName =[combineData objectAtIndex:2];
myInt = [postIndex2 integerValue];
NSLog(#"%ld", (long)myInt);
[self getStadiumDetail];
[self map2];
savedImages = [[NSUserDefaults standardUserDefaults] valueForKey:#"sportsImage"];
sportsName = [[NSUserDefaults standardUserDefaults] valueForKey:#"sportsName"];
if (savedImages.count<1) {
_infoLabel.hidden = NO;
_bookNowBt.hidden = YES;
}
else{
_infoLabel.hidden = YES;
}
[_collectionViewBook reloadData];
[_collectionViewFacility reloadData];
//////////tap gesture
oneTap.numberOfTapsRequired=1;
oneTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:#selector(handleSingleTap332)];
oneTap.delegate = self;
// [ProgressHUD showSuccess:#"" Interaction:YES];
self.btnI.layer.cornerRadius = self.btnI.frame.size.width/2;
[self.btnI.layer setBorderWidth:2.0];
[self.btnI.layer setBorderColor:[[UIColor grayColor] CGColor]];
_moreBt.layer.cornerRadius = 4.0f;
_bookNowBt.layer.cornerRadius = 4.0f;
_rateLbl.layer.borderColor = [UIColor lightGrayColor].CGColor;
_rateLbl.layer.borderWidth = 2.0f;
_rateLbl.layer.cornerRadius =_rateLbl.frame.size.width/2;
_rateLbl.clipsToBounds = YES;
_confirmationLblText.text = [[NSUserDefaults standardUserDefaults] valueForKey:#"savedPayText"];
In the very end ,Nil all the Images you have declared previously.
After every pushtoViewController nil the reference you created for it.
Use #autoreleasepool.
keep weak references for Outlets and assign any strong references to nil** inviewWillDisapper: . You can present a viewController modally as a temporary interruption to obtain important information from the user.
Instead of creating new MKMapView's as needed in the app, I added an mkMapView property to my AppDelegate and only created it when needed. Once it has been created, it lives in the AppDelegate forever and I reuse that single instance everywhere needed. This really helped in reducing the amount of memory being used as I was previously instantiating a couple different MKMapView's and both were burning through memory pretty quickly.
Don’t use -imageNamed i’m saying it again don’t use imageNamed ever method because it caches the images. Use this instead of -imageNamed : (make a method on appDelegate and then call it anywhere you want)
-(UIImage *)method4TakeImagesFromBundel:(NSString *)nameOfImage
{
NSString fileLocation = [[NSBundle mainBundle] pathForResource:nameOftheImage ofType:#"png"];
UIImage yourImage = [[UIImage alloc] initWithContentsOfFile:fileLocation];
return yourImage;
}
After getting the image compress it and use it:
NSData *imgData= UIImageJPEGRepresentation(rainyImage,0.1 /compressionQuality/);
You can further resize it:
(UIImage *)imageWithImage:(UIImage *)image convertToSize:(CGSize)size {
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *destImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return destImage;
}
I am trying to get the keyboard to go away, when I press the return key on my application heres my code from the .m:
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
and the code in the .h:
- (BOOL)textFieldShouldReturn:(UITextField* )textField;
But when I run the application and hit the return key nothing happens. What am I doing wrong?
my .h:
#import <UIKit/UIKit.h>
#interface ChemicalInfoViewController: UIViewController{
IBOutlet UIScrollView *ChemicalInforScroller;
}
#property (strong, nonatomic) IBOutlet UITextField *PPMForChlTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForChlTextField;
#property (strong, nonatomic) IBOutlet UITextField *PPMForAlkTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkTextField;
#property (strong, nonatomic) IBOutlet UITextField *PPMForPHTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForPHTextField;
- (IBAction)SumbitCDI:(UIButton *)sender;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForChl;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForChl;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForAlk;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForAlk;
#property (strong, nonatomic) IBOutlet UILabel *PPMLabelForPH;
#property (strong, nonatomic) IBOutlet UILabel *GallonsLabelForPH;
#property (strong, nonatomic) IBOutlet UITextField *ChlorinePoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PhPoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *AlkPoundsTextField;
#property (strong, nonatomic) IBOutlet UITextField *LbsForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PPMForAlkDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *LbsForPhDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *PPMForPhDecreaser;
#property (strong, nonatomic) IBOutlet UITextField *GallonsForPhDecreaser;
- (IBAction) clickedBackground;
#interface ChemicalInfoViewController : UIView <UITextField>
#end
and my .m:
#import "ChemicalInfoViewController.h"
#interface ChemicalInfoViewController ()
#end
#implementation ChemicalInfoViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[ChemicalInforScroller setScrollEnabled:YES];
[ChemicalInforScroller setContentSize:CGSizeMake(320, 1000)];
self.textField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) clickedBackground {
[self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
In your .h, remove:
- (BOOL)textFieldShouldReturn:(UITextField* )textField;
And it will work as it should, given that in your .h, you conform to the protocol:
#interface yourViewController : UIView <UITextFieldDelegate>
And set up the delegate like so:
yourTextField.delegate = self;
Edit regarding to the #end:
In your .m, add a #end to the bottom; so , it becomes (scroll to the very bottom):
#implementation ChemicalInfoViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[ChemicalInforScroller setScrollEnabled:YES];
[ChemicalInforScroller setContentSize:CGSizeMake(320, 1000)];
self.textField.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) clickedBackground {
[self.view endEditing:YES];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
#end //Here :-)
You didn't set the delegates for your textfields.
In "viewDidLoad" add
_ChlorinePoundsTextField.delegate = self;
_GallonsForAlkDecreaser.delegate = self;
_PhPoundsTextField.delegate = self;
_AlkPoundsTextField.delegate = self;
_LbsForAlkDecreaser.delegate = self;
_PPMForAlkDecreaser.delegate = self;
_LbsForPhDecreaser.delegate = self;
_PPMForPhDecreaser.delegate = self;
_GallonsForPhDecreaser.delegate = self;
none of these methods seemed to be working for some reason but what i did end up doing was creating a DidEndOnExit action and resigned the keyboard under that action for each textfield
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager startRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidAppear:animated]
[[self.locationManager stopRangingBeaconsInRegion: self.rangedRegion]
]}
- (void)viewDidLoad
{
[super viewDidLoad];
self.tagname.text = [self.TagDetail objectForKey:#"Name"];
self.title = [self.TagDetail objectForKey:#"Name"];
NSString *proximity = #"near";
if ([beacon.proximity == CLProximityNear:]) {
NSLog(#"Show near");
[self.near setHidden:(NO)];
[self.far setHidden:(YES)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityFar]) {
NSLog(#"Show");
[self.near setHidden:(YES)];
[self.far setHidden:(NO)];
[self.immediate setHidden:(YES)];
}
else if ([beacon.proximity == CLProximityImmediate]) {
NSLog(#"Show");
[self.near setHidden: (YES)];
[self.far setHidden: (YES)];
[self.immediate setHidden: (NO)];
}
Heres the .h file
#interface TagDetailViewController : UIViewController
#property (nonatomic, strong) PFObject* TagDetail;
#property (strong, nonatomic)IBOutlet UILabel *tagname;
#property (nonatomic, strong)IBOutlet UIImageView *immediate;
#property (nonatomic, strong)IBOutlet UIImageView *near;
#property (nonatomic, strong)IBOutlet UIImageView *far;
#property (nonatomic, strong)IBOutlet UIButton *showOnMap;
#property CLLocationManager *locationManager;
#property CLBeaconRegion *rangedRegion;
#property NSUUID *artemisUUID;
#property CLBeaconMajorValue *major;
#property CLBeaconMinorValue *minor;
#property CLBeacon *proximity;
#end
Its telling me that the variable beacon is not identified, but doing so in the header file as *beacon doesn't remove any errors. What am I doing wrong? Im really new to this language so that is a large part of why Im running into errors, but I cant figure this one out.
You don't have a variable named beacon, you have a CLBeacon object named proximity.
I'm coding a program in Objective C that uses two different views to input data. One view merely displays the view (PSACurrentGame) and the other inputs the data (PSAEnterScores). I'm using a "prepareforsegue" method to pass data from PSAEnterScores to PSACurrentGame. The problem is the label isn't changing. Any idea why?
PSACurrentGame.m :
#import "PSACurrentGame.h"
#import "PSAGlobal.h"
#interface PSACurrentGame ()
#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;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
PSACurrentGame.h:
#import <UIKit/UIKit.h>
#interface PSACurrentGame : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *player1;
#property (strong, nonatomic) IBOutlet UILabel *player2;
#property (strong, nonatomic) IBOutlet UILabel *player3;
#property (strong, nonatomic) IBOutlet UILabel *player4;
#property (strong, nonatomic) IBOutlet UILabel *player5;
#property (strong, nonatomic) IBOutlet UILabel *player6;
#property (strong, nonatomic) IBOutlet UILabel *R1P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP1Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP2Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP3Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP4Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP5Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP6Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP6Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1List2;
#property (strong, nonatomic) IBOutlet UILabel *R2List2;
#property (strong, nonatomic) IBOutlet UILabel *R3List2;
#property (strong, nonatomic) IBOutlet UILabel *ToList2;
#end
PSAEnterScores.m:
#import "PSAEnterScores.h"
#import "PSAGlobal.h"
#import "PSACurrentGame.h"
#interface PSAEnterScores ()
#end
#implementation PSAEnterScores
- (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.player1Name.text = global.player1Name;
self.player2Name.text = global.player2Name;
self.player3Name.text = global.player3Name;
self.player4Name.text = global.player4Name;
self.player5Name.text = global.player5Name;
self.player6Name.text = global.player6Name;
if ([self.player3Name.text isEqualToString:#""] == true) {
self.player3Name.hidden = true;
self.player3txt.hidden = true;
}
if ([self.player4Name.text isEqualToString:#""] == true) {
self.player4Name.hidden = true;
self.player4txt.hidden = true;
}
if ([self.player5Name.text isEqualToString:#""] == true) {
self.player5Name.hidden = true;
self.player5txt.hidden = true;
}
if ([self.player6Name.text isEqualToString:#""] == true) {
self.player6Name.hidden = true;
self.player6txt.hidden = true;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"enterScoresOk"] == true) {
PSACurrentGame *pass = (PSACurrentGame *)segue.destinationViewController;
//Moving scores from round two to round three.
pass.R3P1Score.text = pass.R2P1Score.text;
pass.R3P1Phase.text = pass.R2P1Phase.text;
pass.R3P2Score.text = pass.R2P2Score.text;
pass.R3P2Phase.text = pass.R2P2Phase.text;
pass.R3P3Score.text = pass.R2P3Score.text;
pass.R3P3Phase.text = pass.R2P3Phase.text;
pass.R3P4Score.text = pass.R2P4Score.text;
pass.R3P4Phase.text = pass.R2P4Phase.text;
pass.R3P5Score.text = pass.R2P5Score.text;
pass.R3P5Phase.text = pass.R2P5Phase.text;
pass.R3P6Score.text = pass.R2P6Score.text;
pass.R3P6Phase.text = pass.R2P6Phase.text;
//Moving scores from round 1 to round 2
pass.R2P1Score.text = pass.R1P1Score.text;
pass.R2P2Phase.text = pass.R1P1Phase.text;
pass.R2P2Score.text = pass.R1P2Score.text;
pass.R2P2Phase.text = pass.R1P2Phase.text;
pass.R2P3Score.text = pass.R1P3Score.text;
pass.R2P3Phase.text = pass.R1P3Phase.text;
pass.R2P4Score.text = pass.R1P4Score.text;
pass.R2P4Phase.text = pass.R1P4Phase.text;
pass.R2P5Score.text = pass.R1P5Score.text;
pass.R2P5Phase.text = pass.R1P5Phase.text;
pass.R2P6Score.text = pass.R1P6Score.text;
pass.R2P6Phase.text = pass.R1P6Phase.text;
//Setting Round 1 Scores and Phase
pass.R1P1Score.text = self.player1txt.text;
pass.R1P2Score.text = self.player2txt.text;
pass.R1P3Score.text = self.player3txt.text;
pass.R1P4Score.text = self.player4txt.text;
pass.R1P5Score.text = self.player5txt.text;
pass.R1P6Score.text = self.player6txt.text;
pass.R1P1Phase.text = pass.ToP1Phase.text;
pass.R1P2Phase.text = pass.ToP2Phase.text;
pass.R1P3Phase.text = pass.ToP3Phase.text;
pass.R1P4Phase.text = pass.ToP4Phase.text;
pass.R1P5Phase.text = pass.ToP5Phase.text;
pass.R1P6Phase.text = pass.ToP6Phase.text;
//Setting the total's score and phase.
//Setting Player 1's score and phase.
pass.ToP1Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP1Score.text integerValue] + [self.player1txt.text integerValue])];
if ([pass.ToP1Score.text integerValue] >= 50) {
pass.ToP1Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP1Phase.text integerValue] + 1)];
}
//Setting Player 2's score phase.
pass.ToP2Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP2Score.text integerValue] + [self.player2txt.text integerValue])];
if ([pass.ToP2Score.text integerValue] >= 50) {
pass.ToP2Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP2Phase.text integerValue] + 1)];
}
//Setting Player 3's Score
pass.ToP3Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP3Score.text integerValue] + [self.player1txt.text integerValue])];
if ([pass.ToP3Score.text integerValue] >= 50) {
pass.ToP3Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP3Phase.text integerValue] + 1)];
}
//Setting Player 4's Score
pass.ToP4Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP4Score.text integerValue] + [self.player4txt.text integerValue])];
if ([pass.ToP4Score.text integerValue] >= 50) {
pass.ToP4Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP4Phase.text integerValue] + 1)];
}
//Setting Player 5's Score
pass.ToP5Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP5Score.text integerValue] + [self.player5txt.text integerValue])];
if ([pass.ToP5Score.text integerValue] >= 50) {
pass.ToP5Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP5Phase.text integerValue] + 1)];
}
//Setting Player 6's Score
pass.ToP6Score.text = [NSString stringWithFormat:#"%d", ([pass.ToP6Score.text integerValue] + [self.player6txt.text integerValue])];
if ([pass.ToP6Score.text integerValue] >= 50) {
pass.ToP6Phase.text = [NSString stringWithFormat:#"%d", ([pass.ToP6Phase.text integerValue] + 1)];
}
NSLog(#"Value of P1ToScore: %#", pass.ToP1Score.text);
}
}
- (BOOL) textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
#end
PSAEnterScores.h:
#import <UIKit/UIKit.h>
#interface PSAEnterScores : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *player1txt;
#property (weak, nonatomic) IBOutlet UITextField *player2txt;
#property (weak, nonatomic) IBOutlet UITextField *player3txt;
#property (weak, nonatomic) IBOutlet UITextField *player4txt;
#property (weak, nonatomic) IBOutlet UITextField *player5txt;
#property (weak, nonatomic) IBOutlet UITextField *player6txt;
#property (weak, nonatomic) IBOutlet UILabel *player1Name;
#property (weak, nonatomic) IBOutlet UILabel *player2Name;
#property (weak, nonatomic) IBOutlet UILabel *player3Name;
#property (weak, nonatomic) IBOutlet UILabel *player4Name;
#property (weak, nonatomic) IBOutlet UILabel *player5Name;
#property (weak, nonatomic) IBOutlet UILabel *player6Name;
#end
Log after one time inputing data:
2013-11-25 19:04:08.810 Phase 10 Scoring Application[34601:11303] Unknown class PSA in Interface Builder file.
2013-11-25 19:08:11.607 Phase 10 Scoring Application[34601:11303] Value of P1ToScore: (null)
(The Name of the program is Phase 10 Scoring Application)
I have no idea why it says Unknown class PSA in Interface Builder file. I have no class named "PSA", it is merely the prefix for my classes.
prepareForSegue: is called before viewDidLoad: so your IBOutlet will be nil. Try setting the incoming value to a NSString and then use that string to populate the UIlabel on viewDidLoad:
For example
In your PSACurrentGame.h:
// create a property
#property(nonatomic,strong)NSString *gameName;
In your PSAEnterScores.m: modify your
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
PSACurrentGame *pass = (PSACurrentGame *)segue.destinationViewController;
pass.gameName=[NSString alloc]initWithString:pass.R2P1Score.text]
}
In your PSACurrentGame.m :
- (void)viewDidLoad
{
[super viewDidLoad];
// set text to your label
R3P1Score.text=gameName;
}
I have a problem, I have a couple view controllers. One is called PSACurrentGame, the other is called PSAEnterScores. PSACurrentGame is the parent class for PSAEnterScores. I'm trying to change labels in PSACurrentGame from PSAEnterScores. But I already figured that out with the parent class thing. The real problem is that, while I have the correct property linked with the variable the variable's text won't change. I confirmed that the lanbel responds to changes in the viewDidLoad method, but it won't respond to it being changed in a child class. Does anyone know why?
Code below:
PSACurrentGame.h:
#interface PSACurrentGame : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *R1P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P1Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P1Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP1Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP1Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P2Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P2Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP2Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP2Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P3Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P3Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP3Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP3Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P4Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P4Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP4Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP4Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P5Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P5Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP5Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP5Phase;
#property (strong, nonatomic) IBOutlet UILabel *R1P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R1P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *R2P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R2P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *R3P6Score;
#property (strong, nonatomic) IBOutlet UILabel *R3P6Phase;
#property (strong, nonatomic) IBOutlet UILabel *ToP6Score;
#property (strong, nonatomic) IBOutlet UILabel *ToP6Phase;
#property (strong, nonatomic) IBOutlet UILabel *player1;
#property (strong, nonatomic) IBOutlet UILabel *player2;
#property (strong, nonatomic) IBOutlet UILabel *player3;
#property (strong, nonatomic) IBOutlet UILabel *player4;
#property (strong, nonatomic) IBOutlet UILabel *player5;
#property (strong, nonatomic) IBOutlet UILabel *player6;
#property (strong, nonatomic) IBOutlet UILabel *R1List2;
#property (strong, nonatomic) IBOutlet UILabel *R2List2;
#property (strong, nonatomic) IBOutlet UILabel *R3List2;
#property (strong, nonatomic) IBOutlet UILabel *ToList2;
- (void) updateScores;
#end
PSACurrentGame.m:
#interface PSACurrentGame ()
#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
self.ToP1Score = [[UILabel alloc]initWithFrame:CGRectMake(0,0,100,50)];
[self.ToP1Score setTextColor:[UIColor redColor]];
[self.ToP1Score setFont:[UIFont fontWithName:#"Arial" size:30]];
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;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
PSAEnterScores.h:
#interface PSAEnterScores : PSACurrentGame
#property (weak, nonatomic) IBOutlet UITextField *player1Txt;
#property (weak, nonatomic) IBOutlet UITextField *player2Txt;
#property (weak, nonatomic) IBOutlet UITextField *player3Txt;
#property (weak, nonatomic) IBOutlet UITextField *player4Txt;
#property (weak, nonatomic) IBOutlet UITextField *player5Txt;
#property (weak, nonatomic) IBOutlet UITextField *player6Txt;
#property (weak, nonatomic) IBOutlet UILabel *player1Lbl;
#property (weak, nonatomic) IBOutlet UILabel *player2Lbl;
#property (weak, nonatomic) IBOutlet UILabel *player3Lbl;
#property (weak, nonatomic) IBOutlet UILabel *player4Lbl;
#property (weak, nonatomic) IBOutlet UILabel *player5Lbl;
#property (weak, nonatomic) IBOutlet UILabel *player6Lbl;
#end
PSAEnterScores.m:
#interface PSAEnterScores ()
- (IBAction)ok:(id)sender;
#end
#implementation PSAEnterScores
- (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.player1Lbl.text = global.player1Name;
self.player2Lbl.text = global.player2Name;
self.player3Lbl.text = global.player3Name;
self.player4Lbl.text = global.player4Name;
self.player5Lbl.text = global.player5Name;
self.player6Lbl.text = global.player6Name;
if ([self.player3Lbl.text isEqual:#""]) {
self.player3Lbl.hidden = YES;
self.player3Txt.hidden = YES;
}
if ([self.player4Lbl.text isEqual:#""]) {
self.player4Lbl.hidden = YES;
self.player4Txt.hidden = YES;
}
if ([self.player5Lbl.text isEqual:#""]) {
self.player5Lbl.hidden = YES;
self.player5Txt.hidden = YES;
}
if ([self.player6Lbl.text isEqual:#""]) {
self.player6Lbl.hidden = YES;
self.player6Txt.hidden = YES;
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
- (IBAction)ok:(id)sender {
[self.ToP1Score setText:self.player1Txt.text];
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 // This section is where the ToP1Score should be changed, but it isn't!
NSInteger curScore = [self.ToP1Score.text integerValue];
NSInteger curPhase = [self.ToP1Phase.text integerValue];
self.ToP1Score.text = [NSString stringWithFormat:#"%d", (curScore += [self.player1Txt.text integerValue])];
if ([self.player1Txt.text integerValue] < 50) {
self.ToP1Phase.text = [NSString stringWithFormat:#"%d", (curPhase += 1)];
}
}
- (void) updateScores {
}
#end
If you need anything more just comment, and I'll add.
EDIT: I changed the text at the top, but I'll put it down here too. The label now responds to changes in its own class, but now in child classes. Do child classes only have read-only permission to access parent class variables?
I think you have two things you could improve:
1) Use IBOutletCollection instead of creating one for each of your interface controls;
2) Use a shared datasource and get notified when its values changes. Then you can make changes in your controls, inside their own ViewControllers, like that:
self.dataStore addObserver:self forKeyPath:#"gameScore" options:0 context:nil];
//...
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if ([keyPath isEqual:#"gameScore"]) {
//update your IBOutletCollections...
}
}
Reference
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVOBasics.html#//apple_ref/doc/uid/20002252-BAJEAIEE
I used this example in my application to transfer data between view controllers. So, it may helps: http://iphonedevsdk.com/forum/iphone-sdk-development/54859-sharing-data-between-view-controllers-and-other-objects-link-fixed.html