Save button's new state when exiting the app [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I want to have a button in my app which gets hidden after the first time it's tapped.
So what should I do to save it's hidden property after terminating the app?
And the second thing to ask is almost the same:
How can I change the frame of it after terminating the app?
Thanks in advance

Would probably recommend saving a value in NSUserDefaults Maybe a BOOL for Hidden and check it on start up. An example with a bool would be:
set:
[[NSUserDefaults standardUserDefaults] setBool: YES forKey #"someKey"];
get:
[[NSUserDefaults standardUserDefaults] objectForKey:#"someKey"];
could do the same for any object using:
[[NSUserDefaults standardUserDefaults] setObject: id forKey #"someKey"];

Related

Which method is executed only when app is installed after that it is not executed? [duplicate]

This question already has answers here:
How to detect first time app launch on an iPhone
(17 answers)
Closed 7 years ago.
When app run didFinishLaunch is called either for the first time or when we kill application and again start it. Is there any method which is called only once or at time of installation only?
There is no method which is called only once or at time of installation only.
But you can create this method by using NSUserDefaults. You can add to DidFinishLaunching this code:
if ([[NSUserDefaults standardUserDefaults] objectForKey:#"RunBefore"] == nil)
{
//exec your code
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:#"RunBefore"];
[[NSUserDefaults standardUserDefaults] synchronize];
}

NSLog not printing out BOOL result to console [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a location app that already successfully asks the user to enable location services, and then can show them their coordinates on a button press as well. So I decided to play around with everything that is available in the CLLocationManager reference provided by xcode.
I decided to setup a bool method called "locationServicesEnabled". It returns a value of YES(1) or NO(0). I declared the method and then went to implement it. I am trying to have NSLog print the bool result out to the console when you open the app.
Here is how I declared the BOOL method in my ViewController.m file:
#interface ViewController () <CLLocationManagerDelegate>
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
+ (BOOL)locationServicesEnabled;
#end
And here is how I implemented the BOOL method in ViewController.m:
+ (BOOL)locationServicesEnabled{
[self locationServicesEnabled];
NSLog(#"%hhd", self.locationServicesEnabled);
return 0;
}
Why do you want to create an extra method? You could minimize the risk of errors by using already available ones: NSLog(#"Location services enabled: %d",[CLLocationManager locationServicesEnabled]);
I think your issue might be the fact that you are calling your function inside its self:
+ (BOOL)locationServicesEnabled
{
[self locationServicesEnabled]; <- should this be here
NSLog(#"%hhd", self.locationServicesEnabled);
return 0;
}

App Crashing when Caption isn't there [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
My app displays the Caption of the Instagram Picture and crashes every time there isn't a caption. How would I prevent that from happening? Here is the code that I am using:
if (entry[#"caption"][#"text"]) {
NSString *caption = entry[#"caption"][#"text"];
UILabel *instagramCaptionLabel = (UILabel *)[cell viewWithTag:103];
[instagramCaptionLabel setFont:[UIFont fontWithName:#"Helvetica-Light" size:12.0]];
[instagramCaptionLabel setText:caption];
}
Here is the error:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x1ed8068'
Based on the error message this means you do have a value for #"caption" but it happens to be an NSNull object.
You have two choices:
1) Don't put NSNull values in the dictionary.
or
2) Update your if statement:
if (entry[#"caption"] != [NSNull null] && entry[#"caption"][#"text"] != [NSNull null])

Ios Add objects in a NSMutableArray [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
how can I add an object in an array by clicking a button
I use this methode :
- (void)insertNewObject:(id)sender
{
[orderListe addObject:[[DataOrder alloc]initWithName:#"Michael" price:18 taille:#"junior" supplement:#"boeuf"]];
}
When I do that my application crash and say :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DataOrder initWithName:]: unrecognized selector sent to instance 0x8aa4fa0'
What can i do to simply add an object to an array ?
Thank you
The error your getting has to do with the DataOrder object. During it's initialization it ran into an error. You're sending it some value it isn't expecting.
Perhaps try and separate the line where you alloc the Data Order object and try to add it to the array?
DataOrder *do = [[DataOrder alloc] initWithName....];
[orderListe addObject: do];
this will let you see where you messed up?
Of course that you can add an object to an array. The exception is thrown because the method initWithName:price: ... is not implemented in the DataOrder class.

Getting error when trying to pass integer to method - iOS [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a UIButton which when pressed passes an integer to a simple method I have set up. However I keep on getting this error:
Implicit conversion of 'int' to 'id' is disallowed with ARC
Here is my code:
[self performSelector:#selector(show:) withObject:prev_image afterDelay:2.0];
The reason I'm not just doing [self show:prev_image] is because I want a delay before the method is called.
Thanks for your time, Dan.
You have two choices:
Change the show: method to take an NSNumber and then wrap prev_image in an NSNumber or
Use dispatch_after.
Code:
double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[self show:prev_image];
});
prev_image is an int where an 'object' must be passed into the performSelector method.
I would advise that you do this:
[self performSelector:#selector(show:) withObject:#(prev_image) afterDelay:2.0f];
I would also recommend you change prev_image to prevImage whilst programming in Objective-C simply for style.
Using dispatch_after is not necessary here and you almost certainly want to stay as high level as possible when tackling problems in iOS development.
I apologise for being unclear.
You will also want to change the method signature and implementation of show:
- (void)show:(NSNumber *)number
{
NSInteger integerNumber = [number integerValue];
}
One solution is to use [NSNumber numberWithInt:prev_image] instead of prev_image. Also you'll need to change the show: method to to take an NSNumber instead of an int.

Resources