I have an array of buttons:
pokemon_cards = [[NSMutableArray alloc] init];
[pokemon_cards addObject:self.cardButton1];
[pokemon_cards addObject:self.cardButton2];
[pokemon_cards addObject:self.cardButton3];
later in some method I want to do a BOOL check to see if ALL of them are NOT selected simultaneously. In other words, if ALL of them are not selected notify user, otherwise proceed, even if just one of them is selected.
Here is what i've done but its not working and I can't figure out how to do this without adding the buttons in the loop to a temporary array:
-(BOOL)userCanProceedToTurn {
for (UIButton *button in pokemon_cards) {
if (![button isSelected]) {
// This only works for OR condition I want it to work for &&
return NO;
} else {
return YES;
}
}
}
So this is what I want it to do pretty much but the function above doesn't work for &&:
if (![self.cardButton1 isSelected] && ![self.cardButton2 isSelected] && ![self.cardButton3 isSelected]) {
//notify users they must selected at least one card
} else {
}
But i don't know which cards will be added to the array, that depends on the user, so I don't know how to check for that in the for loop
EDIT
I have implemented the code as suggested below. and as mentioned before this does not the && check that I was concerned with.
For example i need to make sure ALL cards are not currently in the 'not selected' state. but if one of those 3 cards are then they can proceed, even if the other two aren't. but with the check below, it will not proceed because the else statement is in the loop as well so everytime the loop is ran the buttons that aren't selected cause it to not proceed because the loop is ran 3 times.
here is my complete bool method, everything else works fine except the button one:
-(BOOL)userCanProceedToTurn {
if (self.energyAmount == 0) {
UIAlertView *view .. tell users they need energy before proceeding
return NO;
}
if (self.usernameLabel.text.length == 0) {
//Tell user they are not signed in
return NO;
}
NSLog(#"button is %lu", (unsigned long)pokemon_cards.count);
for (UIButton *button in pokemon_cards) {
if ([button isSelected]) {
NSLog(#"button.tag == %lu",button.tag);
return YES;
} else {
UIAlertView *view .. tell users they need to select at least one card
//this gets called because the loop is ran as many times there are buttons so inevitably i'll get an error. Which is why this works for the first button only, because it stops looping after it found that one since it was the first once selected
return NO;
}
}
return YES;
}
Do you actually need to know the state of each button?
Why not take the opposite approach:
- (BOOL)userCanProceedToTurn {
for (UIButton *button in pokemon_cards) {
if ([button isSelected]) {
return YES;
}
}
return NO;
}
EDIT
As a rule of thumb, methods that return a BOOL value should start with a flag set to YES or NO and only invert that flag, never setting it back to its original value. So basically, start with with BOOL result = YES and only flip it to NO, never ever flip it back to YES. This will have the pseudo-security of preventing something bad to happen.
Here's your method rewritten with this concept:
- (BOOL)userCanProceedToTurn {
BOOL isEverythingOK = NO;
NSString *message = nil;
if (self.energyAmount != 0) {
isEverythingOK = YES;
} else {
message = #"You need energy before proceeding.";
}
if (self.usernameLabel.text.length != 0) {
isEverythingOK = YES;
} else {
message = #"You are not signed in.";
}
for (UIButton *button in pokemon_cards) {
if ([button isSelected]) {
isEverythingOK = YES;
} else {
message = #"You need to select at least one card"
}
}
if (!isEverythingOK) {
UIAlertView *alert = [[UIAlertView alloc] initWith use the message here]
}
return isEverythingOK
}
We can sum up the questions, answers and comments. You can use these methods to do what you want :)
- (BOOL)userCanProceedToTurn
{
// Check Username
if (self.usernameLabel.text.length == 0)
{
[self showMessage: #"You are not signed in."];
return false;
}
// Check Energy
if (!(energyAmount > 0))
{
[self showMessage: #"You need energy before proceeding."];
return false;
}
// Check Cards
for (UIButton *button in pokemon_cards)
{
if ([button isSelected])
{
return true
}
}
[self showMessage: #"You need to select at least one card"];
return false;
}
- (void)showMessage:(NSString *)title
{
[[[UIAlertView alloc] initWithTitle: title message: nil delegate: nil cancelButtonTitle: #"OK" otherButtonTitles: nil] show];
}
If you need to know which buttons are selected then try
-(BOOL)userCanProceedToTurn
{
NSMutableArray *pokemon_cards_temp = [[NSMutableArray alloc] init];
for (UIButton *button in pokemon_cards)
{
if ([button isSelected])
{
[pokemon_cards_temp addObject:button];
}
}
// Do what you want with the selected buttons
if ([pokemon_cards_temp count] > 0)
{
return true;
}
else
{
return false;
}
}
Related
Xcode 7.3, iOS 9.3.1
I want to use two custom overlay views for when the user is about to take a picture and after while editing the picture. To change the overlay I would like to know if there is a callback method from the UIImagePickerControllerDelegate that will let me know when the user starts editing the picture, or when the user has tapped the take picture button.
The only methods I know of are:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
I have looked here: UIImagePickerController with cameraOverlayView focusses when button in overlay is tapped, How to know I tap "taking photo button" with UIImagePicker and iOS - Taking A Picture After Button Tap in UIImagePickerController CustomOverlayView.
Or perhaps there is a way to get the tap event from the standard button by adding an observer.
Please help! Thanks in advance.
you could use the UINavigationControllerDelegate that you also have to implement when using UIImagePickerController. implementing the delegate method [...]didShowViewController[...] like this
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
NSLog(#"%#", [viewController class]);
}
produces the following output (using the simulator, choosing UIImagePickerControllerSourceTypePhotoLibrary as the sourceType and navigating like this: photo albums overview > specific album > editing specific photo):
2016-04-08 00:19:36.882 ImagePicker[44578:4705834] PUUIAlbumListViewController
2016-04-08 00:19:41.341 ImagePicker[44578:4705834] PUUIMomentsGridViewController
2016-04-08 00:19:47.929 ImagePicker[44578:4705834] PUUIImageViewController
hope that helps!
UIImagePickerControllerDelegate is quite poor but you can handle it by adding an observer:
Swift 3:
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "_UIImagePickerControllerUserDidCaptureItem"), object:nil, queue:nil, using: { note in
//Do something
})
Objective-C:
[[NSNotificationCenter defaultCenter] addObserverForName:#"_UIImagePickerControllerUserDidCaptureItem" object:nil queue:nil usingBlock:^(NSNotification * _Nonnull note) {
//Do something
}];
Xcode 8.2.1, iOS10.2.1
Before implementing please read the solution for earlier version to understand the basics. Thanks! The problem was that some of the names for various subviews have changed from iOS 9.3.1 to iOS 10.2.1.
Here is the complete code (see below where to insert), that replaces "//Code goes here" below:
for (UIView *subviewImagePickerControllerView in self.imagePickerController.view.subviews)
{
if ([subviewImagePickerControllerView.class.description isEqualToString:#"UINavigationTransitionView"])
{
for (UIView *subviewUINavigationTransitionView in subviewImagePickerControllerView.subviews)
{
if ([subviewUINavigationTransitionView.class.description isEqualToString:#"UIViewControllerWrapperView"])
{
for (UIView *subviewUIViewControllerWrapperView in subviewUINavigationTransitionView.subviews)
{
if ([subviewUIViewControllerWrapperView.class.description isEqualToString:#"CAMCameraViewControllerContainerView"])
{
for (UIView *subviewCAMCameraViewControllerContainerView in subviewUIViewControllerWrapperView.subviews)
{
if ([subviewCAMCameraViewControllerContainerView.class.description isEqualToString:#"CAMViewfinderView"])
{
for (UIView *subviewCAMViewfinderView in subviewCAMCameraViewControllerContainerView.subviews)
{
if ([subviewCAMViewfinderView.class.description isEqualToString:#"CAMBottomBar"])
{
for (UIView *subviewCAMBottomBar in subviewCAMViewfinderView.subviews)
{
if ([subviewCAMBottomBar.class.description isEqualToString:#"CUShutterButton"] && [subviewCAMBottomBar.class isSubclassOfClass:[UIButton class]])
{
UIButton *shutterButton = (UIButton *)subviewCAMBottomBar;
[shutterButton addTarget:self action:#selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
}
else
{
nil;
}
}
}
}
}
else if ([subviewCAMCameraViewControllerContainerView.class.description isEqualToString:#"PLCropOverlay"])
{
for (UIView *subviewPLCropOverlay in subviewCAMCameraViewControllerContainerView.subviews)
{
if ([subviewPLCropOverlay.class.description isEqualToString:#"PLCropOverlayBottomBar"])
{
for (UIView *subviewPLCropOverlayBottomBar in subviewPLCropOverlay.subviews)
{
if ([subviewPLCropOverlayBottomBar.class.description isEqualToString:#"PLCropOverlayPreviewBottomBar"])
{
for (UIView *itemPLCropOverlayPreviewBottomBar in subviewPLCropOverlayBottomBar.subviews)
{
if ([itemPLCropOverlayPreviewBottomBar.class isSubclassOfClass:[UIButton class]])
{
UIButton *buttonPLCropOverlay = (UIButton *)itemPLCropOverlayPreviewBottomBar;
if ([buttonPLCropOverlay.titleLabel.text isEqualToString:#"Retake"])
{
UIButton *retakeButton = buttonPLCropOverlay;
[retakeButton addTarget:self action:#selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];
}
else
{
nil;
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
Xcode 7.3, iOS9.3.1
I had to get this working, so I spent a lot of time figuring this out.
The gist of it is, I drill down the view hierarchy after the UIImagePickerController was presented, looking for CMKShutterButton and the retake button with a title of "Retake", then I attach a selector to the buttons' action, like so...
[shutterButton addTarget:self action:#selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
[retakeButton addTarget:self action:#selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];
Drop the code below into the completion block that is called after your image picker is presented:
[self presentViewController:self.imagePickerController animated:true completion:^(void){
//Code goes here
}
Here is the complete code, that replaces "//Code goes here" above:
for (UIView *subviewImagePickerControllerView in self.imagePickerController.view.subviews)
{
if ([subviewImagePickerControllerView.class.description isEqualToString:#"UINavigationTransitionView"])
{
for (UIView *subviewUINavigationTransitionView in subviewImagePickerControllerView.subviews)
{
if ([subviewUINavigationTransitionView.class.description isEqualToString:#"UIViewControllerWrapperView"])
{
for (UIView *subviewUIViewControllerWrapperView in subviewUINavigationTransitionView.subviews)
{
if ([subviewUIViewControllerWrapperView.class.description isEqualToString:#"PLImagePickerCameraView"])
{
for (UIView *subviewPLImagePickerCameraView in subviewUIViewControllerWrapperView.subviews)
{
if ([subviewPLImagePickerCameraView.class.description isEqualToString:#"CMKBottomBar"])
{
for (UIView *itemCMKBottomBar in subviewPLImagePickerCameraView.subviews)
{
if ([itemCMKBottomBar.class.description isEqualToString:#"CMKShutterButton"] && [itemCMKBottomBar.class isSubclassOfClass:[UIButton class]])
{
UIButton *shutterButton = (UIButton *)itemCMKBottomBar;
[shutterButton addTarget:self action:#selector(touchUpInsideCMKShutterButton) forControlEvents:UIControlEventTouchUpInside];
}
else
{
nil;
}
}
}
else if ([subviewPLImagePickerCameraView.class.description isEqualToString:#"PLCropOverlay"])
{
for (UIView *subviewPLCropOverlay in subviewPLImagePickerCameraView.subviews)
{
if ([subviewPLCropOverlay.class.description isEqualToString:#"PLCropOverlayBottomBar"])
{
for (UIView *subviewPLCropOverlayBottomBar in subviewPLCropOverlay.subviews)
{
if ([subviewPLCropOverlayBottomBar.class.description isEqualToString:#"PLCropOverlayPreviewBottomBar"])
{
for (UIView *itemPLCropOverlayPreviewBottomBar in subviewPLCropOverlayBottomBar.subviews)
{
if ([itemPLCropOverlayPreviewBottomBar.class isSubclassOfClass:[UIButton class]])
{
UIButton *buttonPLCropOverlay = (UIButton *)itemPLCropOverlayPreviewBottomBar;
if ([buttonPLCropOverlay.titleLabel.text isEqualToString:#"Retake"])
{
UIButton *retakeButton = buttonPLCropOverlay;
[retakeButton addTarget:self action:#selector(touchUpInsideButtonRetake) forControlEvents:UIControlEventTouchUpInside];
}
else
{
nil;
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
}
else
{
nil;
}
}
And here is the method I am attaching, which goes in the view controller that is presenting the image picker controller:
- (void)touchUpInsideCMKShutterButton
{
NSLog(#"Take");
}
- (void)touchUpInsideButtonRetake
{
NSLog(#"Re-take");
}
Hope this helps someone! Thanks.
I have aUITextField and below that 3 button. User can enter the amount inUITextField. And When user clicked the button belowUITextField it will add the amount inUITextField with amount written in button.
First button will add 100, Second will add 500 ad 3rd will add 1000. What is the best method to achieve it.
I try to implement following but got button.tag=0
/*Amount increment*/
- (IBAction)Btn_Incr100:(id)sender {
[self addTextFieldValue:nil];
}
- (IBAction)Btn_Incr500:(id)sender {
[self addTextFieldValue:nil];
}
- (IBAction)Btn_Incr1000:(id)sender {
[self addTextFieldValue:nil];
}
-(void)tagNumber{
Btn_Incr100.tag=1;
Btn_Incr500.tag=2;
Btn_Incr1000.tag=3;
}
-(void) addTextFieldValue:(UIButton*) button
{
int amount=[Txt_Amount.text intValue];
int AddAmount;
NSLog(#"button.tag%d",button.tag);
if (button.tag==1) {
AddAmount=100;
}
else if (button.tag==2) {
AddAmount=500;
}
else if(button.tag==3) {
AddAmount=1000;
}else{
AddAmount=0;
}
amount=amount+AddAmount;
Txt_Amount.text=[NSString stringWithFormat:#"%d",amount];
NSLog(#"%d",amount);
NSLog(#"%#",Txt_Amount.text);
}
Try using it by implementing tag
- (void)viewDidLoad {
[super viewDidLoad];
[self tagNumber];
}
-(void)tagNumber{
Btn_Incr100.tag=1;
Btn_Incr500.tag=2;
Btn_Incr1000.tag=3;
}
-(void) addTextFieldValue:(UIButton*) button
{
int amount=[Txt_Amount.text intValue];
int AddAmount;
int buttonTagIndex = button.tag;
switch (buttonTagIndex) {
case 1:
AddAmount=100;
break;
case 2:
AddAmount=500;
break;
case 3:
AddAmount=1000;
break;
default:
AddAmount=0;
break;
}
amount=amount+AddAmount;
Txt_Amount.text=[NSString stringWithFormat:#"%d",amount];
}
- (IBAction)btnAmountClick:(id)sender{
UIButton *button = sender;
[self addTextFieldValue:button];
}
With the help of this you can achieve:
-(void)displayvalue:(id)sender {
UIButton *resultButton = (UIButton *)sender;
NSLog(#" The button's title is %#." resultButton.currentTitle);
}
and now you can set this text inside your textfield.
Add this method as every button action.
-(void) addTextFieldValue:(UIButton*) button
{
NSString *string;
if ([button.text hasPrefix:#"+"] && [button.text length] > 1)
{
string = [string substringFromIndex:1];
}
int textFieldValue =[textField.text integerValue] + string.integerValue;
textField setText:[NSString stringWithFormat:#"%i",textFieldValue];
}
NSString *string;
if ([button.text hasPrefix:#"+"] && [button.text length] > 1)
{
string = [string substringFromIndex:1];
}
int textFieldValue =[textField.text integerValue] + string.integerValue;
textField setText:[NSString stringWithFormat:#"%i",textFieldValue];
or
connect separate actions
-(IBAction) onClick1: (id) sender]
{
NSLog(#"User clicked %#", sender);
textField.text = [textField.text integerValue] + 100
}
You can do this way -
The three buttons below your textfield, link them all to a common method say,
-(IBAction)addBtnClicked:(UIButton *)btn
Given tags to three buttons like for button 100,
btn1.tag=100..
then for button 500,
btn2.tag = 500..
then for button 1000, btn2.tag = 1000.
then in
-(IBAction)addBtnClicked:(UIButton *)btn
{
int value = -1;
if(btn.tag == 100)
{
value =[txtFldText.text intValue] + 100;
}
else if(btn.tag == 500)
{
value =[txtFldText.text intValue] + 500;
}
else if(btn.tag == 1000)
{
value =[txtFldText.text intValue] + 1000;
}
txtFldText.text = [NSString stringWithFormat:#"%d",value];
}
Simply you can do like this:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_txtAmount.text=#"0";
_btn100.tag=100;
_btn500.tag=500;
_btn1000.tag=1000;
}
- (IBAction)btnAmountClick:(id)sender
{
UIButton *btn=sender;
if (btn.tag==100)
{
[self addAmount:#"100"];
}
if (btn.tag==500)
{
[self addAmount:#"500"];
}
if (btn.tag==1000)
{
[self addAmount:#"1000"];
}
}
-(void)addAmount:(NSString*)strAmount
{
int amount=[_txtAmount.text intValue]+[strAmount intValue];
_txtAmount.text=[NSString stringWithFormat:#"%d",amount];
}
First set tag to every button like 0,1,2.
then connect IBOutlet of all button to single IBAction and
implement the IBAction as below.
- (IBAction)btnClicked:(id)sender
{
switch ([sender tag]) {
case 0:
{
NSString *s=self.txtField.text;
int add=[s intValue]+ 100;
self.txtField.text=[NSString stringWithFormat:#"%d",add];
break;
}
case 1:
{
NSString *s=self.txtField.text;
int add=[s intValue]+ 200;
self.txtField.text=[NSString stringWithFormat:#"%d",add];
}
break;
case 2:
{
NSString *s=self.txtField.text;
int add=[s intValue]+ 500;
self.txtField.text=[NSString stringWithFormat:#"%d",add];
}
break;
default:
break;
}
}
There's a better solution for this.
You can use tags smth differently, as they are.
Just tie your three buttons as actions to this method and set the tags to 100/500/1000
- (void)buttonAction:(id)sender {
textField.text = [NSString stringWithFormat:#"%li", (long)(textfield.text.intValue + sender.tag)];
}
I am creating a custom delegate UIAlertView's alert:buttonClickedAtIndex: method, but it is not working properly. I am subclassing a UIView, and I have two buttons that are tagged as 0 and 1. This still does not work when I go to check the delegate for my custom view. Here the code that I did.
Custom View
- (void) buttonTouchedWithIdentifier:(NSInteger)identifier
{
if (identifier == 0) {
[self.delegate alert:self didClickButtonWithTagIdentifier:0];
}
if (identifier == 1) {
[self.delegate alert:self didClickButtonWithTagIdentifier:1];
}
}
* in my showInViewMethod *
[self.dismissButton addTarget:self action:#selector(buttonTouchedWithIdentifier:) forControlEvents:UIControlEventTouchDown];
[self.continueButton addTarget:self action:#selector(buttonTouchedWithIdentifier:) forControlEvents:UIControlEventTouchDown];
self.dismissButton.tag = 0;
self.continueButton.tag = 1;
* in my view controller *
nextLevelAlert = [[ARAlert alloc] init];
nextLevelAlert.delegate = self;
[nextLevelAlert showInView:self.view
withMessage:[NSString stringWithFormat:#"Congratulations, you have completed level %i.\nWould you like to continue?", levelNumber]
dismissButtonTitle:#"Menu"
continueButtonTitle:#"Next Level"];
- (void)alert:(ARAlert *)alert didClickButtonWithTagIdentifier:(NSInteger)tagId
{
if (alert == nextLevelAlert) {
if (tagId == 0) {
NSLog(#"User does not want to continue.");
}
}
}
Now, nextLevelAlert has the delegate set to self, and I do have the delegate declared in my view controller's class. Also, when i do the showInView... for nextLevelAlert, it DOES appear, it is recognizing what button is being pressed.
My guess is your param is not a NSInteger but the button, you should change buttonTouchedWithIdentifier like this :
- (void) buttonTouchedWithIdentifier:(id)sender
{
UIButton *button = (UIButton*)sender;
NSLog(#"buttonTouchedWithIdentifier %#",#(button.tag));
if (button.tag == 0) {
[self.delegate alert:self didClickButtonWithTagIdentifier:0];
}
if (button.tag == 1) {
[self.delegate alert:self didClickButtonWithTagIdentifier:1];
}
}
Also when comparing two objects use isEqual: instead of ==
- (void)alert:(ARAlert *)alert didClickButtonWithTagIdentifier:(NSInteger)tagId
{
if ([alert isEqual:nextLevelAlert]) {
if (tagId == 0) {
NSLog(#"User does not want to continue.");
}
}
}
How to know if there is a UIActionSheet showing in View Hierarchy?
Also I want to get a reference to that UIActionSheet, any good idea?
Notice that on iOS6, you need a recursive search to finde the UIActionSheet, it is not a direct subview of UIWindow now.
static UIView *actionSheet = nil;
-(void)findActionSheetInSubviewsOfView:(id)view
{
if (actionSheet) {
return;
}
if ([[view valueForKey:#"subviews"] count] != 0) {
for (id subview in [view valueForKey:#"subviews"]) {
if ([subview isKindOfClass:[UIActionSheet class]]) {
actionSheet = subview;
}
else
[self findActionSheetInSubviewsOfView:subview];
}
}
}
-(UIActionSheet*) actionSheetShowing {
actionSheet = nil;
for (UIWindow* window in [UIApplication sharedApplication].windows) {
[self findActionSheetInSubviewsOfView:window];
}
if (actionSheet) {
return (UIActionSheet*)actionSheet;
}
return nil;
}
I'm stuck with this weird problem.I have a method that clears the related UIObjects values which works fine in simulator and debug mode using ipad but after archiving and downloading same app (adhoc release) the method shows different behavior.As it work fine in debug mode I'v traced using alert in every conditions of method and it shows different behavior.
//Method
-(void)NAclicked:(UIViewController *)controller ofId:(id)sender
{
UIView *newCheck = (UIView * )sender;
int i=newCheck.tag;
NSLog(#"id %d",i);
bool fromGroup4 = [controller isKindOfClass:[G4S16_FunctionalStatusEvaluation class]];
if([newCheck isKindOfClass:[CheckBoxNE class]] || ([controller isKindOfClass:[G4S16_FunctionalStatusEvaluation class]] && [sender isKindOfClass:[CheckBoxNASN class]]))
{
bool condition = false;
if(fromGroup4)
{
CheckBoxNASN* cb = (CheckBoxNASN*)sender;
condition = ([cb.Value isEqualToString:#"NA"]);
}
else
{
CheckBoxNE* cb = (CheckBoxNE*)sender;
if([[cb Value] intValue]==1)
{
NSLog(#"%d",([[cb Value] intValue]==1));
condition = true;
}
}
if(condition)
{
NSManagedObject *question =[self getQuestionObjectFromQuestionElementId:((UIButton *)sender).tag];
int questionId = [[question valueForKey:#"id"]intValue];
NSArray *arrQuestionElements= [self getQuestionElementsFromQuestion:questionId];
for(int j=0;j<[arrQuestionElements count];j++)
{
QuestionElements *questionElements = [arrQuestionElements objectAtIndex:j];
NSLog(#"Question Element %#",questionElements.id);
if([questionElements.id intValue]==i)
continue;
UIView *new = (UIView * )[controller.view viewWithTag:[questionElements.id intValue]];
if([new isKindOfClass:[UIButton class]])
{
UIButton* btnDD = (UIButton*)new;
[btnDD setTitle:#"" forState:UIControlStateNormal];
btnDD.titleLabel.text=#"";
[self saveAnswer:btnDD.tag AnswerText:#""];
}
else if([new isKindOfClass:[DWOptionGroup class]])
{
DWOptionGroup* btnCB = (DWOptionGroup*)new;
[btnCB setValue:#""];
[self saveAnswer:btnCB.tag AnswerText:#""];
}
else if([new isKindOfClass : [CheckBox class]])
{
CheckBox* btnCB = (CheckBox*)new;
[btnCB setValue:0];
[self saveAnswer:btnCB.tag AnswerText:#""];
}
else if([new isKindOfClass : [UITextField class]])
{
UITextField * txtCB = (UITextField *)new;
txtCB.text=#"";
[self saveAnswer:txtCB.tag AnswerText:#""];
}
else
{
//testing
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Testing"
message:#"nothing to clear."
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"Ok",nil];
[alert show];
//
}
}
}
}
else
{
[self removeNA:controller ofId:sender];
}
}
Conditions and results
In debug mode
if there are four question elements (i.e arrQuestionElements.count=4).
1)UIButton
2)DWOptionGroup
3)CheckBox
4)UITextField
in each loop it enter respective if conditions.
1st loop=if([new isKindOfClass:[UIButton class]])
2nd loop=else if([new isKindOfClass:[DWOptionGroup class]])
and so on.
But in adhoc release for same condition traced using alert.
1st loop=else part
2nd loop=else part
3rd loop=else part
and
4th loop=else if([new isKindOfClass : [UITextField class]]) (works fine for last of the loop)
similarly,if the last object is UIButton
1st loop=else part
2nd loop=else part
3rd loop=else part
and
4th loop=if([new isKindOfClass:[UIButton class]]) (works fine for last of the loop)
Any suggestion regarding this issue would be highly appreciated.
Thank you.