开发者

What could possibly be wrong in this IF-Conditional statement?

What could possibly be the error in this ??

int flag11 = 1;


if (([self.textField1.text length]>0) &&  
    ([self.textField4.text length]>0) && 
    ([self.textField3.text length]>0) && 
   (([self.textField2.text length]>0) || (flag11)))
    {
               NSLog(@"Please display me");

               // Some statements //
    }

Here, first three conditions are TRUE. And th开发者_开发问答e last one should obviously be TRUE because of flag11 being 1.

It breaks out with error Current language: auto; currently objective-c (gdb) and Program received error: SIGABRT and does not enter inside IF statement as expected.


Note: If I remove flag11, and I have just those four conditions, it works! What I want to know is why does it report an error when flag11 is added to the code.


That's weird. I made a sample project with 4 textfields and a button hooked up to an action which does your check, and NSLog's the results and it seemed to work fine. Here's the code if you want to see:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITextFieldDelegate> {

  IBOutlet UITextField * textField1;
  IBOutlet UITextField * textField2;
  IBOutlet UITextField * textField3;
  IBOutlet UITextField * textField4;

}

@property (nonatomic, retain) IBOutlet UITextField * textField1;
@property (nonatomic, retain) IBOutlet UITextField * textField2;
@property (nonatomic, retain) IBOutlet UITextField * textField3;
@property (nonatomic, retain) IBOutlet UITextField * textField4;

- (IBAction)buttonPress;

@end

#import "ViewController.h"

@implementation ViewController

@synthesize textField1;
@synthesize textField2;
@synthesize textField3;
@synthesize textField4;

- (void)dealloc; {
  [super dealloc];
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; {
  return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField; {
  if(textField == textField1){
    [textField1 resignFirstResponder];
  }
  else if(textField == textField2){
    [textField2 resignFirstResponder];
  }
  else if(textField == textField3){
    [textField3 resignFirstResponder];
  }
  else{
    [textField4 resignFirstResponder];
  }
  return YES;
}

- (IBAction)buttonPress; {

  int flag11 = 1;

  if (([self.textField1.text length]>0) &&  
      ([self.textField4.text length]>0) && 
      ([self.textField3.text length]>0) && 
      (([self.textField2.text length]>0) || (flag11)))
  {
    NSLog(@"Please display me");

    // Some statements //
  }
  else{
    NSLog(@"Nothing");
  }
}

@end

One thing I got stuck on was that you put textField2 being the one that does not require any text. (lol) I guess the only thing to make sure is that the 4 textfields are hooked up to the right IBOutlet, and that the file's owner is the delegate for each one as well. Hope that helps!


SIGABRT means that you are trying to accessing something that isn't there. Did you created all the textfield's properly and/or drag the right connection in IB?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜