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.
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;
My app crashes with this stack trace:
[DictationDetailsController respondsToSelector:]: message sent to deallocated instance
I tracked that on instruments trying to see the relevant code causing the crash:
here is the relevant code for MyDictationController in the didSelectRowAtIndexPath: delegate method:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath {
DictationDetailsController *controller = GET_CONTROLLER_WITH_CLASS([DictationDetailsController class]);
controller.dictation = [unSubmittedDictations objectAtIndex:indexPath.row];
controller.isEditMode = YES;
controller.selectedDate = _selectedDate;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#property (copy ,nonatomic) Dictation *dictation;
Also i have used #synthesize. Help me out in this issue, to get which deallocated method is being called.?
Here's my DictationDetailsController interface:
#interface DictationDetailsController : BaseController
#property (copy ,nonatomic) Dictation *dictation;
#property (nonatomic) BOOL isEditMode;
#property (nonatomic) NSDate *selectedDate;
#property (weak, nonatomic) IBOutlet UILabel *navigationTitleLabel;
#property (weak, nonatomic) IBOutlet UITextField *patientNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *accountIDTextField;
#property (weak, nonatomic) IBOutlet UITextField *workTypeTextField;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidth;
#property (weak, nonatomic) IBOutlet UIView *tutorialView;
#property (weak, nonatomic) IBOutlet UIView *audioContainer;
#property (weak, nonatomic) IBOutlet UISlider *audioSlider;
#property (weak, nonatomic) IBOutlet UILabel *durationLabel;
#property (weak, nonatomic) IBOutlet UILabel *noRecordingLabel;
#property (weak, nonatomic) IBOutlet UIButton *playPauseButton;
#end
And in dealloc method:
- (void)dealloc {
[player pause];
player = nil;
self.dictation = nil;
}
My guess is the issue is somewhere inside GET_CONTROLLER_WITH_CLASS method. Pop a breakpoint on that line and step over it. It's possibly producing a released instance of the class. That being the case, the crash would occur on the line immediately following the call to that method when it tries to access the dictation property.
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
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;