I'm expecting to get a little help with a UIButtons staying .hidden. I'm new to this site so please give me a min to best describe this problem I face.
Below is a picture of 2 UIButtons, in the middle of these UIButtons there is another one called OnRoute. Once the Acknowledged button is pressed it is hidden to which sends a status and reveals the OnRoute UIButton. Now the Acknowledged button is hidden you will only see on screen under the Runsheet button the OnRoute button to which you also press that sends a status and then hides it self.
Once these buttons are pressed you are sent to a UITableView and at this point all is well, but when you go back to the menu screen the buttons are reappear as if the buttons have not been pressed. And you can repeat over and over sending status.
The idea of this is to send a job status once the buttons are pressed which in turn shows on software on a server. Once these have been sent and the UIButtons hide for that job number, I would like to keep them hides until job has gone from hand set.
This is complex problem but if anyone has any ideas of this, I would really be thankful.
//This is in ViewDidLoad
self.onroute.hidden = YES;
NSNumber *num = [NSNumber numberWithInt:10.00];
self.acknow.hidden = YES;
if((self.consignment.cur_status_no < num) || [self.consignment.newjob isEqual:#(YES)]){
self.acknow.hidden = NO;
//This is in IBAction
- (IBAction)acknowledgebtn:(id)sender {
if (self.onroute.hidden == YES){
self.acknow.hidden = NO;
self.onroute.hidden = NO;
self.acknow.hidden = YES;
//and this is for the other IBAction
if (self.acknow.hidden == YES){
self.onroute.hidden = YES;
As I'm new to the site it will not let me post picture of UIButton sorry for this.
My suggestion would be to use some booleans instead of relying on the buttons hidden property. Then save the booleans when transferring to a new view. Then when you return to the main menu check the booleans and see what should be hidden and what should not be.
Also when I name variables I like to pretend that someone else will be looking at my code. So instead of just onroute as the button name, I would make it onrouteBut. This makes it a lot easier when I go back through my code as well so I know exactly what each variable is just by looking at the name.
As for the code I don't know how you are presenting views, so I can't really give a full answer. But I think this will help.
in your .h
#property (nonatomic) BOOL onrouteBool;
#property (nonatomic) BOOL acknowBool;
//whatever other bools you need instead of using button.hidden == YES/NO
in your .m
#synthesize onrouteBool, acknowBool;
-(void)viewDidLoad {
onrouteBut.hidden = YES;
onrouteBool = YES;
NSNumber *num = [NSNumber numberWithInt:10.00];
acknowBut.hidden = YES;
acknowBool = YES;
if((self.consignment.cur_status_no < num) || [self.consignment.newjob isEqual:#(YES)]) {
acknowBut.hidden = NO;
acknowBool = NO;
}
}
-(IBAction)acknowledgeBtn:(id)sender {
if (onrouteBool == YES) {
acknowBut.hidden = NO;
onrouteBut.hidden = NO;
acknowBool = NO;
onrouteBool = NO;
//this part doesn't make sense you set the button to visible and then hidden right after
acknowBut.hidden = YES;
acknowBool = YES;
}
}
-(IBAction)onrouteBtn:(id)sender {
if (acknowBool == YES) {
onrouteBut.hidden = YES;
onrouteBool = YES;
}
}
So now before you transition to your next view call this method to save the bools
-(void)saveTheBools {
//save the bools however you want before you transition the view
//one way is nsuserdefaults
[[NSUserDefaults standardUserDefaults]setBool:onrouteBool forKey:#"onrouteBool"];
[[NSUserDefaults standardUserDefaults]setBool:acknowBool forKey:#"acknowBool"];
[[NSUserDefaults standardUserDefaults]synchronize];
//how you save them
}
then when you transition back to the main menu check the bools to see if the buttons should be hidden
-(void)checkTheBools {
onrouteBool = [[NSUserDefaults standardUserDefaults] boolForKey:#"onrouteBool"];
acknowBool = [[NSUserDefaults standardUserDefaults] boolForKey:#"acknowBool"];
if (onrouteBool == YES) {
onrouteBut.hidden = YES;
}
else {
onrouteBut.hidden = NO;
}
if (acknowBool == YES) {
acknowBut.hidden = YES;
}
else {
acknowBut.hidden = NO;
}
//whatever else you need to hidden or make visible
}
This is all just to give you some ideas of what to do. Use what you need to make it work. This is how I would do it, I don't know if this is best way to do it but it's a starting point. I can't really give a specific answer without seeing all of your code, since I don't know how you're transitioning views, what you are initializing, retaining, etc.
Hope this helps you out, if not my bad. Just keep working at it and you'll find something that works for you eventually.
edit:
As for the status problem you are having I can't really help because I don't have the code to look at. I think it probably has to do with saving your variables so you can access them across classes. So like I showed you how to save the booleans and use them you probably will have to do something similar to check if the status has sent or not.
I suggested using nsuserdefaults because that is the easiest thing to do, however it is not the best to rely on that for saving all of your variables. You can also look into singletons, core data, or anything that will allow you to save the variables that you need across classes. You just have to find the way that works best for what you are trying to do.
The only way you are going to learn is to struggle at times, do some research, and try different things until you find a solution. Also take advantage of the resources apple provides you with as a developer. I think you will be able to figure this one out. Good luck
Just wanted to update anyone having this problem, I managed to fix this using doubleValue.
onroute.hidden = YES;
onrouteBool = YES;
NSNumber *num1 = [NSNumber numberWithDouble:10.00];
if(([self.consignment.cur_status_no doubleValue] < [num1 doubleValue] ) ) {
if([self.consignment.newjob isEqual:#(NO)]) {
onroute.hidden = NO;
onrouteBool = NO;
}
}
acknow.hidden = YES;
acknowBool = YES;
if([self.consignment.newjob isEqual:#(YES)]) {
acknow.hidden = NO;
acknowBool = NO;
}
Thanks again for all your help.
Related
I am having a hard time figuring out how to get my quick actions working when I launch my app with a quick action.
My quick actions work, however, if the app was in the background and re-launched with the quick action.
When I try to launch the app straight from the quick action, the app opens as if it was launched by simply tapping the app icon (i.e. it does nothing).
Here is some code from my App Delegate.
In didFinishLaunchingWithOptions:
UIApplicationShortcutItem *shortcut = launchOptions[UIApplicationLaunchOptionsShortcutItemKey];
if(shortcut != nil){
performShortcutDelegate = NO;
[self performQuickAction: shortcut fromLaunch:YES];
}
The method called:
-(BOOL) performQuickAction: (UIApplicationShortcutItem *)shortcutItem fromLaunch:(BOOL)launchedFromInactive {
NSMutableArray *meetings = [self.fetchedResultController.fetchedObjects mutableCopy];
[meetings removeObjectAtIndex:0];
unsigned long count = meetings.count;
BOOL quickActionHandled = NO;
if(count > 0){
MainViewController *mainVC = (MainViewController *)self.window.rootViewController;
if(launchedFromInactive){
mainVC.shortcut = shortcutItem;
}
else{
UINavigationController *childNav;
MeetingViewController *meetingVC;
for(int i = 0; i < mainVC.childViewControllers.count; i++){
if([mainVC.childViewControllers[i] isKindOfClass: [UINavigationController class]]){
childNav = mainVC.childViewControllers[i];
meetingVC = childNav.childViewControllers[0];
break;
}
}
self.shortcutDelegate = meetingVC;
if ([shortcutItem.type isEqual: #"Meeting"]){
NSNumber *index = [shortcutItem.userInfo objectForKey:#"Index"];
[self.shortcutDelegate switchToCorrectPageWithIndex: index launchedFromInactive:NO];
quickActionHandled = YES;
}
}
}
The only action that needs to be performed is that my page view controller (which is embedded inside the meetingVC) should switch to a certain page with respect to the shortcut chosen.
Any ideas on what causes the shortcut to not do anything when using it to launch as opposed to re-opening the app from the background??
I came to realize I was trying to call my methods on a view controller that was not in memory yet. This was causing bizarre behavior in my app. I did have the correct approach to getting access to the view controller and then it dawned on me the possibility of trying to execute the code using GCD.
__block MeetingViewController *safeSelf = self;
contentVC = [self initializeContentViewController: self.didLaunchFromInactive withPageIndex: intIndex];
NSArray *viewControllers = #[contentVC];
dispatch_async(dispatch_get_main_queue(), ^{
[safeSelf.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
});
The above worked like magic, and the shortcuts are leading to the correct page. Using a similar approach to mine hopefully yields the desired results for anyone else who wanted to get their shortcuts working by launching the app.
I'm developing a calculator app and would like to add 10 storage registers that the User can store numbers to. The calculator's storyboard has a "STO" button that is pressed when the User wants to store an entry. The next numeric button pressed (button 0, button 1 ... button 9) would signify the register to store the entry in.
The app currently contains the method "STOButtonPressed":
- (IBAction)STOButtonPressed:(UIButton *)sender{
STOButtonPressed = YES;
}
I have a method for entering numbers into the calculator, called digitPressed:
- (IBAction)digitPressed:(UIButton *)sender{
NSString* digit = sender.currentTitle;
[_audioPlayer play];
if(!(self.dotNotation && [digit isEqualToString:#"."])){
if([digit isEqualToString:#"."])
self.dotNotation=YES;
if(self.userIsInTheMiddleOfTyping){
self.displayLabel.text = [self.displayLabel.text stringByAppendingString:digit];
}
else
{
self.displayLabel.text = digit;
self.userIsInTheMiddleOfTyping = YES;
}
}
}
Each number button on the calculator in the storyboard is tagged (button "0" is tag "0", button "1" is tag "1", etc....).
After pressing the "STO" button, I'd like the next button (0 thru 9) entry to be the storage register number. And I'd like to set the storage register number within the STOButtonPressed method. Not sure if that's possible, or how to do it if it is. I currently have several "IF statements" in the digitPressed method for determining the storage register number (not shown here). But that seems very cumbersome and the method has gotten very messy. I'd like to keep all code for the storage feature within the STOButtonPressed method. I've been working this unsuccessfully for many days, and feel I'm missing something. Can someone tell me how to make set the storage register number within the STOButtonPressed method, if that's even possible?
I'm using Xcode 5.
If you have set your button's tags properly, it should be pretty straightforward:
in your properties, add:
#property (nonatomic, assign) BOOL hasPressedSTOButton;
and change this because you don't want confusion between your var and your method name:
- (IBAction)STOButtonPressed:(UIButton *)sender{
self.hasPressedSTOButton = YES;
}
And change your tags to 1-10 instead of 0-9 because you want to make sure you are checking a button with a non-zero tag, and not some other button.
then change your digitPressed like this
- (IBAction)digitPressed:(UIButton *)sender{
NSString* digit = sender.currentTitle;
[_audioPlayer play];
if(!(self.dotNotation && [digit isEqualToString:#"."])){
if([digit isEqualToString:#"."])
self.dotNotation=YES;
if(self.userIsInTheMiddleOfTyping){
self.displayLabel.text = [self.displayLabel.text stringByAppendingString:digit];
}
else
{
self.displayLabel.text = digit;
self.userIsInTheMiddleOfTyping = YES;
}
} else if (sender.tag != 0) {
//store your stuff here. Tags range from 1 to 10. Use sender.tag - 1 if you want the values to range from 0 to 9.
}
}
In my program I used a void method and I want to stop this when the button action is done.
in viewDidLoad
[self runningaction];
and out side of the viewDidLoad
-(void)runningaction
{
some code
}
another method for UIButton action
-(void)clicktosee
{
//here i need to write code for stop the -(void)runningaction
}
Thanks in advance.
Put check that method is implemented then just return that's what i tried
-(void)clicktosee
{
if( [self respondsToSelector:#selector(runningaction)] ) {
return;
}
}
Ok, if I understood your question (and comment) correctly, you want to start some animations on button images, and then stop them on user action.
This can be achieved like this :
-(void)runningaction {
myButton.imageView.animationImages =
[NSArray arrayWithObjects:[UIImage imageNamed:#"image1.png"],
[UIImage imageNamed:#"image2.png"],
nil];
myButton.imageView.animationDuration = 0.5; //whatever you want (in seconds)
myButton.imageView.animationRepeatCount = 0; //0 means repeat forever here
[myButton.imageView startAnimating];
}
Then in -(void)clicktosee you simple write this line : [myButton.imageView stopAnimating].
Hope I understood you correctly.
NOTE : The animation code is taken from this answer by #ender.
How can i fix this kind of problems
here is some code
BOOL missed = NO;
if (elem.lastCall.lastMissedEvent) {
if ([elem.status intValue] == 3 && [elem.timeStamp compare:elem.lastCall.lastMissedEvent] != NSOrderedAscending) {
missed = YES;
}
}
SCBubbleViewOut *bubble = nil;
if ([cell.bubbleView isKindOfClass:[SCBubbleViewOut class]]) {
bubble = (SCBubbleViewOut *) cell.bubbleView;
}
or here is some more code snipet
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *userid = [members objectAtIndex:indexPath.row];
BOOL itsMe = NO;
if ([userid isEqualToString:[SCUserProfile currentUser].userid]) {
itsMe = YES;
[self performSegueWithIdentifier:#"SCUserProfileControllerSegue" sender:self];
}
else
{
[self showFriendDetailForUserid:userid];
}
}
from these cases i get
Value stored to "BOOL" is never read;
BOOL = itsMe , missed and bubble.
Any help is highly appreciated
Thanks in Advance.
Well, you are storing some value into a variable "missed", and you are never using the value stored. So the compiler is wondering why you are doing this, because it is pointless, and the compiler assumes that maybe you wanted to do something else.
If you stored the variable for example so that you can view it in the debugger, add a line
(void) missed;
That tells the compiler "yes, I know I store a value and I'm not using it, leave me alone". On the other hand, if that's not the case then you need to figure out what you actually wanted to do. The compiler doesn't know, and we don't know. The compiler just says "this doesn't look right", and I can only agree with it.
I have four text fields in a ViewController, and want to disable the keyboard for two of them (textField1 and textField2).
I have tried implementing the following after assigning the text fields as delegates in viewDidLoad
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField) {
if ([self.textField1 isTouchInside] || [self.textField2 isTouchInside] {
return NO;
} else {
return YES;
}
}
However, this disables the keyboard for the ViewController completely, so it will not appear when trying to edit textField3 and textField4. How can I get around this problem?
For example, is there a way to refresh the run textFieldShouldBeginEditing method again after editing ends on a textField?
Also, I know I can create a label to accomplish something similar, but I would prefer to use a text field in my case.
EDIT: So I left out a big detail. I am firing an IBaction when pressing textField1 and 2. However, Lootsch's answer gave me an idea.
In the textField1/2Pressed IB action, I ran the textfield.enable:NO methods, then I re-enabled them when I fired a second action which submitted data to the textfields, such as below
- (IBAction)textField1Pressed:(id)sender {
self.textField.Enabled = NO;
}
- (IBAction)submitToTextField1:(id)sender {
self.textField.text = #"blah blah";
self.textField.Enabled = YES;
}
Albeit, this requires having two entering an exiting actions, but it worked for me. Also, I did not have to manipulate the textFieldShouldBeginEditing method with this solution.
You should disable these two textFields (in code or via IB) or you can disable the user interactions (different appearance, same function):
textField3.enabled = NO;
textField4.enabled = NO;
Or:
textField3.userInteractionEnabled = NO;
textField3.userInteractionEnabled = NO;
The second approach won't change the appearance of the UITextFields, while the first will indicate, that these TextFields are disabled.
something like should do
if (textField==textField1 || textField==textField2) [textField resignFirstResponder];
Please try this
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField==self.textField1 || textField==self.textField2)
{
return NO;
}
else
{
return YES;
}
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)mytextField
{
if((mytextField.tag == 104) || (mytextField.tag == 105) || (mytextField.tag == 106))
{
if(mytextField.tag == 104)
{
point = 50;
// if(textField1.tag == 4)
{
[self showDatePickerWithTitle:#"Select DOB"];
return NO;
}
//
}
}
else
{
retutn YES;
}
//you can also try this piece of code.With tag property of textfield.And make sure your tag is not zero,because the default tag is 0 for the main view.