ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UICollectionViewDataSource,UICollectionViewDelegate>
#property (weak, nonatomic) IBOutlet UIScrollView *mainScrollView;
#property (weak, nonatomic) IBOutlet UICollectionView *NewPrciousCltnVw;
#property (weak, nonatomic) IBOutlet UICollectionView *NewFashionCltnVw;
+ (NSString *)stringVariable;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
+ (NSString *)proVariable;
#property (weak, nonatomic) IBOutlet UIScrollView *imageSlider;
#property (weak, nonatomic) IBOutlet UILabel *lblNewArrivals;
#property (weak, nonatomic) IBOutlet UILabel *lblFeaturedProducts;
#property (weak, nonatomic) IBOutlet UILabel *roundedoffers;
#property (weak, nonatomic) IBOutlet UIView *lbloffers;
#property (weak, nonatomic) IBOutlet UIScrollView *offersSlider;
#end
This is my Storyboard
Here ViewController is the 'front-view' of SWRevealViewController and Menu ViewControler is the 'rear-view'.If I continuously use push to SecondViewController and back to ViewController for more than 3 minutes my app gets crashed. Somebody help me out from this issue and thanks in advance
Related
So I was making an app on Xcode ( Objective C) and I really am not able to find a way to fix it
Can somebody please help me with this?
#import "ViewController.h"
#import "DistanceGetter/DGDistanceRequest.h"
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UITextField *startLocation;
#property (nonatomic) DGDistanceRequest *req;
#property (weak, nonatomic) IBOutlet UITextField *endLocationA;
#property (strong, nonatomic) IBOutlet UIView *distanceA;
#property (weak, nonatomic) IBOutlet UITextField *endLocationB;
#property (weak, nonatomic) IBOutlet UILabel *distanceB;
#property (weak, nonatomic) IBOutlet UITextField *endLocationC;
#property (weak, nonatomic) IBOutlet UILabel *distanceC;
#property (weak, nonatomic) IBOutlet UIButton *calculateButton;
#end
#implementation ViewController
- (IBAction)calculateButtonTapped:(id)sender {
self.calculateButton.enabled=NO;
self.req = [DGDistanceRequest alloc];
NSString *start = self.startLocation.text;
NSString *destA = self.endLocationA.text;
NSString *destB = self.endLocationA.text;
NSString *destC = self.endLocationA.text;
NSArray *dests = #[destA,destB,destC];
self.req = [self.req initWithLocationDescriptions:dests
sourceDescription:start];
self.req.callback= void(ˆNSArray *responses)
self.distanceC.text=#"callback";
self.calculateButton.enabled = YES;
self.req=nil;
When I make it ˆvoid(NSArray.....) it gives even more errors
You have a typo :
void(^... should be ^void(... - the error is somewhat misleading, and it seems strange than Xcode didn’t suggest a „Fix-it”.
Anyway, I recommend http://goshdarnblocksyntax.com/ to remind yourself with block syntax.
I have an array of UIButton objects (I have 5 buttons so I wanted to store them in an array for easy processing). But Array give me error
"Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[__NSArray0 addObject:]:
unrecognized selector sent to instance"
#property (weak, nonatomic) IBOutlet UIButton *starOne;
#property (weak, nonatomic) IBOutlet UIButton *starTwo;
#property (weak, nonatomic) IBOutlet UIButton *starThree;
#property (weak, nonatomic) IBOutlet UIButton *starFour;
#property (weak, nonatomic) IBOutlet UIButton *starFive;
#property (nonatomic, copy) NSMutableArray *_starButtons;
I have below code in viewDidLoad method
- (void)viewDidLoad {
self._starButtons=[[NSMutableArray alloc]init];
[self._starButtons addObject:self.starOne];
[self._starButtons addObject:self.starTwo];
[self._starButtons addObject:self.starThree];
[self._starButtons addObject:self.starFour];
[self._starButtons addObject:self.starFive];
NSLog(#"%#",self._starButtons);
}
Please help me where i am going wrong.
First remove copy from declaration of array property, make it strong.
Second thing as you have said in comment that you have programmatically created buttons then you not need IBOutlets. So, remove IBOutlets from all properties of button.
Your declaration should like,
#property (weak, nonatomic) UIButton *starOne;
#property (weak, nonatomic) UIButton *starTwo;
#property (weak, nonatomic) UIButton *starThree;
#property (weak, nonatomic) UIButton *starFour;
#property (weak, nonatomic) UIButton *starFive;
#property (nonatomic, strong) NSMutableArray *_starButtons;
Try this:
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UIButton *one;
#property (weak, nonatomic) IBOutlet UIButton *two;
#property (weak, nonatomic) IBOutlet UIButton *three;
#end
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray *buttonArray = [[NSMutableArray alloc] initWithObjects:one,two,three,nil];
NSLog(#"%#",buttonArray);
}
If you're using Storyboard or Nib file then:
Another approach is to connect the UIButtons' to an NSArray of IBOutletCollection in Interface Builder, instead of adding manually each button to an NSMutableArray. Something like this for all UIButtons'.
#property (nonatomic, retain) IBOutletCollection(UIButton) NSArray *buttonsArray;
Just one change in code.
Replace this line:
#property NSMutableArray *_starButtons;
I am having trouble, from calling a variable from view controller.h. I am new to coding.
-(IBAction)buttonReset:(UIButton *)sender{
[self resetBoard];
}
-(void)resetBoard{
s0.image = NULL;
s1.image = NULL;
s2.image = NULL;
s3.image = NULL;
s4.image = NULL;
s5.image = NULL;
s6.image = NULL;
s7.image = NULL;
s8.image = NULL;
viewcontroller.h code
#property (weak, nonatomic) IBOutlet UIButton *resetButton;
#property (weak, nonatomic) IBOutlet UIImageView *s0;
#property (weak, nonatomic) IBOutlet UIImageView *s1;
#property (weak, nonatomic) IBOutlet UIImageView *s2;
#property (weak, nonatomic) IBOutlet UIImageView *s3;
#property (weak, nonatomic) IBOutlet UIImageView *s4;
#property (weak, nonatomic) IBOutlet UIImageView *s5;
#property (weak, nonatomic) IBOutlet UIImageView *s6;
#property (weak, nonatomic) IBOutlet UIImageView *s7;
#property (weak, nonatomic) IBOutlet UIImageView *s8;
Are you mean that the buttonReset method is not be called when you click the button?
Make sure you synthesize all s0, s1, s2, etc in your implementation file. Use #synthesize otherwise you'll have to call these variables with an underscore prefixed like _s0, _s1, etc.
I declare my .h file like this:
#import <UIKit/UIKit.h>
#interface NavigationTripViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>{
NSArray *questionTitleTrip;
NSArray *questionDescTrip;
NSMutableArray *answerTrip;
NSMutableArray *pickerChoices;
int questionInt;
int totalInt;
IBOutlet UILabel *questionNum;
IBOutlet UILabel *questionTotalNum;
IBOutlet UILabel *recordType;
IBOutlet UITextView *questionDes;
IBOutlet UIView *answerView;
IBOutlet UIButton *preButton;
IBOutlet UIButton *nextButton;
UITextField *text;
UIPickerView *picker;
}
#property (retain, nonatomic) NSArray *questionTitleTrip;
#property (retain, nonatomic) NSArray *questionDescTrip;
#property (retain, nonatomic) NSMutableArray *answerTrip;
#property (retain, nonatomic) NSMutableArray *pickerChoices;
#property (retain, nonatomic) IBOutlet UILabel *questionNum;
#property (retain, nonatomic) IBOutlet UILabel *questionTotalNum;
#property (retain, nonatomic) IBOutlet UILabel *recordType;
#property (retain, nonatomic) IBOutlet UITextView *questionDes;
#property (retain, nonatomic) IBOutlet UIView *answerView;
#property (retain, nonatomic) IBOutlet UIButton *preButton;
#property (retain, nonatomic) IBOutlet UIButton *nextButton;
#property (retain, nonatomic) UITextField *text;
#property (retain, nonatomic) UIPickerView *picker;
-(IBAction)clickPre;
-(IBAction)clickNext;
#end
And my .m file here like this:
#import "NavigationTripViewController.h"
#import <QuartzCore/QuartzCore.h>
#interface NavigationTripViewController ()
#end
#implementation NavigationTripViewController
#synthesize questionTitleTrip,questionDescTrip,answerTripl,pickerChoices,questionNum,questionTotalNum,recordType,questionDes,answerView,preButton,nextButton,text,picker;
All my variables in the #synthesize receive the warnings:
Autosynthesized property 'myVar' will use synthesized instance variable '_myVar', not existing instance variable 'myVar'
Also, the variables and class names used in viewDidLoad don't display in colors, just show in black color. In other view controllers, there are no warnings like this. How to fix these problems?
Edit:
Basically for all intents and purposes you should be building on a new enough XCode to use the new behavior, in that solution you typically will just remove the ivar from the #interface block in the .h file... If for some reason you do need to access an ivar directly you can now declare it in the #implementation block... and use #synthesize var or #synthesize var=_var
OGPost:
to make that go away you can go all new school and drop the iVar, or you can go all old school and add an #synthesize someIvar in your #implementation block.
My code in my .h file is
#property (weak, nonatomic) IBOutlet UITextField *textFieldTask;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *buttonDone;
and the error shows up
#synthesize of 'weak' property is only allowed in ARC or GC mode
when I replace the weak with strong, the button doesn't work
I can't put it in ARC mode( it will destroy my project)
Anything I can Do?
you need to use retain or assign if you don't want to use ARC
retain
#property (retain, nonatomic) IBOutlet UITextField *textFieldTask;
#property (retain, nonatomic) IBOutlet UIBarButtonItem *buttonDone;
assign
#property (assign, nonatomic) IBOutlet UITextField *textFieldTask;
#property (assign, nonatomic) IBOutlet UIBarButtonItem *buttonDone;