Xcode 5 - ios 7 - Unlock Levels when one level is completed - ios

I have the main viewcontrols with 3 levels (3 x UIButtons) . The first one is visible while the other two are hidden.
The second and third levels are going to be visible just when the previous level is completed.
For example in level 1 when i chose the right question level 2 button became visible and so on.
here an example
Is there a simple way to achieve this? I am new to xcode and I just cannot figure out how to connect the continue button to unhide the level.
here the link with the project file.
http://salvonostrato.com//ex/xcode5/TESTlevels2.zip
Any help is appreciated
In ViwController.h i have:
#import <UIKit/UIKit.h>
#import "Levell1ViewController.h"
#interface ViewController : UIViewController {
IBOutlet UIButton *level1;
IBOutlet UIButton *level2;
IBOutlet UIButton *level3;
}
-(IBAction)unhide:(id)sender;
#end
then in ViewControl.m I have implemented
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)unhide:(id)sender{
level2.hidden = NO;
level3.hidden = NO;
}
}
-(IBAction)hide:(id)sender{
level2.hidden = YES;
level3.hidden = YES;
}
}
In Livell1ViewControl.h i have called a button
#import <UIKit/UIKit.h>
#interface Levell1ViewController : UIViewController
#property (nonatomic, weak) UIButton *nextlevel2;
#end
The result does not have any issues however, it crashes when the load.
here the upgraded project
http://salvonostrato.com//ex/xcode5/TESTlevels2.zip

Related

When adding UIView instantiated with an .xib to the Storyboard buttons don't work and background color can't be changed

I am working on an iOS project and wanted to include a UIView that is reused on multiple screens in the application (appearing at the bottom of different UIViews). I am using a storyboard for the UI work so far but created an .xib file to be used by the reusable view (playerView in code below).
The view gets added but the button I have added to the View is unresponsive, also my background color cannot be changed on the view. I have tried to set background color programmatically and in the .xib with no luck. Very weird symptoms and I tried to instantiate the view from #5 of this article and probably did something wrong. I dont fully understand everything in the article which makes me nervous - for instance my showSubclassedView method returns IBAction but I just call the function name in code and dont use a button (I did hook up the buttons in the view as the article described though).
Here is the code:
EventViewController.m (where I trry and add PlayerView)
#import "EventViewController.h"
#import "PlayerView.h"
#interface EventViewController ()
-(IBAction)showSubclassedView;
#end
#implementation EventViewController
-(IBAction)showSubclassedView
{
[PlayerView presentInViewController:self];
}
PlayerView.h (.h for reusable view)
#import <UIKit/UIKit.h>
#import "Utils.h"
#class PlayerView;
#protocol PlayerViewDelegate
-(void)playerViewTouchedUp:(PlayerView*) playerView;
-(void)playerViewDidDismiss:(PlayerView*) playerView;
#end
#interface PlayerView : UIView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate>*) playerView;
-(IBAction)viewTouchedUp;
-(IBAction)dismiss;
#end
PlayerView.m (.m for reusable view)
#import "PlayerView.h"
#interface PlayerViewOwner : NSObject
#property(nonatomic,weak) IBOutlet PlayerView *playerView;
#end
#implementation PlayerViewOwner
#end
#interface PlayerView ()
#property (nonatomic, weak) UIViewController <PlayerViewDelegate> *delegateViewController;
#end
#implementation PlayerView
+(void)presentInViewController:(UIViewController<PlayerViewDelegate> *)viewController
{
PlayerViewOwner *owner = [PlayerViewOwner new];
[[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:owner options:nil];
owner.playerView.delegateViewController = viewController;
[viewController.view addSubview:owner.playerView];
}
-(IBAction)viewTouchedUp
{
//forward to delegate
NSLog(#"you clicked a button");
[self.delegateViewController playerViewTouchedUp:self];
}
-(IBAction)dismiss
{
[self removeFromSuperview];
// Forward to delegate
[self.delegateViewController playerViewDidDismiss:self];
}
#end
PlayerView.xib has a UIbutton on it that connects it to viewTouchedUp method in PLayerView.m
Is there anything I did wrong in the code above? Is this the best way to do a reusable view to display on other views?
Thank you!
Here's a workaround I found after not being able to solve this.
New implementation is from this article
I reverted my changes from my initial question and implemented this. It lacks the nice protocol separation for talking back and forth and I might need something like this later but I think now I can still implement a protocol to solve this.
At least with this solution I have usable items in my view and a background that changes!

Cannot create new outlets in interface builder, old ones have a warning symbol

I am not sure what is causing this problem, but I now cannot create outlets. When I create an outlet it appears and works fine in code, but does not appear under the view controller in storyboard. Old outlets have a warning symbol on them like this
When I remove this outlet, its gone and does not appear back to connect. I am running Xcode beta 6.2 because moving to 6.2 temporarily fixed this problem because I was having it beforehand in 6.1.
Here is the .h file of this class
#import <UIKit/UIKit.h>
#interface DashboardViewController : UITableViewController {
NSString *currentDay;
}
#property (nonatomic, weak) IBOutlet UILabel *dayLabel;
#property (nonatomic, weak) IBOutlet UILabel *blockLabel;
#property (nonatomic, weak) IBOutlet UILabel *currentClassLabel;
#end
and here are the outlets listed in storyboard
These are the details of the warning, but this is .h file's code for this class
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface InfoViewController : UIViewController {
IBOutlet UIScrollView *AISScrollView;
IBOutlet MKMapView *AISMapView;
}
-(IBAction)studentHandbook:(id)sender;
#end
Oddly enough, I ended up finding a solution and that was moving the project out of the directory that it was in. It was in my Dropbox folder and moving it out fixed. If anyone has this problem in the future and also happens to have the proj in their Dropbox, move it out.
try to change this:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface InfoViewController : UIViewController {
IBOutlet UIScrollView *AISScrollView;
IBOutlet MKMapView *AISMapView;
}
-(IBAction)studentHandbook:(id)sender;
#end
to that:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#interface InfoViewController : UIViewController {
}
#property (nonatomic,weak) IBOutlet UIScrollView *AISScrollView;
#property (nonatomic,weak) IBOutlet MKMapView *AISMapView;
-(IBAction)studentHandbook:(id)sender;
#end
Just in case someone suffers from the same thing again, the best answer inside this other thread did the trick for me:
XCode 6: can't connect any IBOutlet to ViewController
Removing the .h and .m files from the project (their references) and readding them again was the solution that worked for me.

Segmented Control- Change label text in another view

I have 2 views 1) ViewController and 2)ViewController2.
In the first view controller I have some lablels that when I run the segment controller the names change. All I want to do is, in (Viewcontroller2) where I have a label, I want it to be able to change the text as well based on the segmented controller being 0 or 1. Here is what I have.
// ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UISegmentedControl *Lang;
IBOutlet UIButton *Run;
IBOutlet UILabel *bet;
}
-(IBAction)ChangeLang:(id)sender;
#end
Then in the m file i have the following to change the data
// ViewController.m
#import "ViewController.h"
#import "ViewController2.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)ChangeLang :(id)sender {
if (Lang.selectedSegmentIndex==0)
{
bet.text=#"Apple";
Run.titleLabel.text=#"Banana";
//not sure here what code to put in order to make the label in viewcontroller2 change.
}
if (Lang.selectedSegmentIndex==1) {
bet.text=#"ORANGES";
Run.titleLabel.text=#"FRUITS";
//not sure here what code to put in order to make the label in viewcontroller2 change.
}
}
This runs fine... heres what I have in VIEWController 2
// Viewcontroller2.h
#import <UIKit/UIKit.h>
#interface ViewController2 : UIViewController
IBOutlet UILabel *Nextword;
#end
In the M controller i just have this
#import "ViewController2.h"
#import "ViewController.h"
#interface ViewController2 ()
#end
How would I, when I run the segmented controller, make the uilabel text change in the ViewController2? Can anyone help? I dont want the screen to go to viewcontroller automatically, I was able to do that. I want the text to change, and then when i swipe to go there, i want the text in Viewcontroller2 to be according to the if statement based on the segmented controller.
Thank you
You need to have an access to instance of ViewController2 from ViewController.
Use this code inside your ViewController.h file:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController{
IBOutlet UISegmentedControl *Lang;
IBOutlet UIButton *Run;
IBOutlet UILabel *bet;
ViewConstroller2 * VC2;
}
-(IBAction)ChangeLang:(id)sender;
#end
When you're creating instance of ViewController2 store it in VC2 variable.
Then use this code as your UISegmentedControl change event:
-(IBAction)ChangeLang:(id)sender {
if (Lang.selectedSegmentIndex==0)
{
bet.text=#"Apple";
Run.titleLabel.text=#"Banana";
VC2.Nextword= "YOUR_WORD";
}
if (Lang.selectedSegmentIndex==1) {
bet.text=#"ORANGES";
Run.titleLabel.text=#"FRUITS";
VC2.Nextword= "YOUR_WORD";
}
}

Updating UILabel in Child View 1 after Global Variable Update in Child View 2

I have made a simple app to test this and cannot figure it out. I have an iPad storyboard where I have put two container views as shown below. I have a label in one view and a button in another. My button will increment the label, 1 number at a time.
My problem is not passing the value or incrementing, but getting the view to load the new value.
Each container has its own ViewController
Some code below, although very sparse as Ive written a bunch and deleted as it didn't work. Please help with the correct format. I would like to keep this general format, updating global variable within button and it updating the label.
LabelViewController.h
#import <UIKit/UIKit.h>
#interface LabelViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *checkLabel;
-(void)loadLabel;
#end
LabelViewController.m
#import "LabelViewController.h"
#import "ParentViewController.h"
#interface LabelViewController ()
#end
#implementation LabelViewController
#synthesize checkLabel;
-(void)loadLabel{
checkLabel.text = [NSString stringWithFormat:#"%d",value];
[self.view setNeedsDisplay];
}
- (void)viewDidLoad
{
[self loadLabel];
[super viewDidLoad];
}
ButtonViewController.h
#import <UIKit/UIKit.h>
#interface ButtonViewController : UIViewController
- (IBAction)checkButton:(id)sender;
#end
ButtonViewController.m
#import "ButtonViewController.h"
#import "ParentViewController.h"
#import "LabelViewController.h"
#interface ButtonViewController ()
#end
#implementation ButtonViewController
- (IBAction)checkButton:(id)sender {
value++;
NSLog(#"%d",value);
LabelViewController *fnc = [[LabelViewController alloc] init];
[fnc loadLabel];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
Picture at:
http://farm4.staticflickr.com/3822/9469907420_746db25b23_b.jpg
In ButtonViewController, you don't want to be alloc init'ing an instance of LabelViewController -- the one that's on screen already exists. Both child view controllers are instantiated just before the parent controller is. So, what you need to do is get a reference to the LabelViewController that's on screen. You can do that with self.parentViewController.childViewControllers[0] (that 0 might have to be 1 -- I don't know which controller is which).
LabelViewController *fnc = self.parentViewController.childViewControllers[0];
[fnc loadLabel];

Hide a button on a view from an other view iphone sdk

I have 2 Views, the first named "InterfaceController", and second named "LoginController".
On LoginController, I have a button "Connexion", and I want when I click on this one, I'd like the button I called "TEST" be hidden.
So I tried :
Interfacecontroller.h :
#interface InterfaceController : UIViewController {
- (IBAction)TEST:(id)sender;
- (IBAction)LoginSwitch:(id)sender;
}
Logincontroller.h :
#interface LoginController : UIViewController {
}
- (IBAction)Connexion:(id)sender;
#end
Logincontroller.m :
#import "InterfaceController.h"
#import "LoginController.h"
#implementation LoginViewController
- (IBAction)Connexion:(id)sender {
[self dismissModalViewControllerAnimated:YES];
InterfaceController.TEST.hidden = YES; (this is what I want to set)
}
.........
I don't really know how to do this, but I think it's easy.
Somebody can explain me ?
You have to add an outlet of test button in interfaceController.h:
#property (nonatomic,strong) IBOutlet UIButton *TEST;
after that in Interface Builder you have to link this Outlet to the Test Button.
At this point your code works

Resources