小编Que*_*ons的帖子

如何在iOS中检查NSString中的NULL值?

我有一个NSString,我想检查它是否有NULL值.如果是,那么if条件应该执行.否则它应该执行else条件.

以下是我使用的代码:

if ([appDelegate.categoryName isEqual:[NSNull null]])
{
    select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster LEFT JOIN Category ON ContentMaster.CategoryID=Category.CategoryID where ContentMaster.ContentTagText='%@'", appDelegate.tagInput];
}
else
{
    select = [[NSString alloc] initWithFormat:@"select * FROM ContentMaster LEFT JOIN Category ON ContentMaster.CategoryID=Category.CategoryID LEFT JOIN Topic ON ContentMaster.TopicID=Topic.TopicID where ContentMaster.ContentTagText='%@' && Category.CategoryName='%@' && Topic.TopicName='%@'", appDelegate.tagInput, appDelegate.categoryName, appDelegate.topicName];
}    
Run Code Online (Sandbox Code Playgroud)

它总是执行else条件,而不是if条件,即使值是NULL.

null nsstring ios

6
推荐指数
1
解决办法
3万
查看次数

如何使文本字段只接受iphone中的4位数或数字

我有一个应用程序,我想在其中输入数值UITextField.但我想只允许输入4位数字.因此1234有效但无法输入12345.知道我怎么能修改它只接受限制为4位的数值?

iphone objective-c uitextfield ios

5
推荐指数
1
解决办法
2万
查看次数

如何验证iPhone应用程序中的URL

如何检查iphone应用程序,如果URL有效,那么它应该打开它,否则它可能会显示它是无效的URL.我正在使用以下代码,但问题是,如果我输入www.google.com它显示有效,如果我输入nice.com也显示有效.

       - (BOOL)textFieldShouldReturn:(UITextField *)textField
      {

       [textField setUserInteractionEnabled:YES];
       [textField resignFirstResponder];
       test=textField.text;

       NSLog(@"Test is working and test is %@",test);

   if ([self  urlIsValiad:test]) {
    NSURL *url = [NSURL URLWithString:test]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    [webView setScalesPageToFit:YES];
    [self.webView loadRequest:request]; 
     } else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please enter Valid URL"  message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];
     }

   return YES;



    }

  - (BOOL) urlIsValiad: (NSString *) url 


 {

NSString *regex = 
@"((?:http|https)://)?(?:www\\.)?[\\w\\d\\-_]+\\.\\w{2,3}(\\.\\w{2})?(/(?<=/)(?:[\\w\\d\\-./_]+)?)?";
/// OR use this 
///NSString *regex = "(http|ftp|https)://[\w-_]+(.[\w-_]+)+([\w-.,@?^=%&:/~+#]* [\w-\@?^=%&/~+#])?";
NSPredicate …
Run Code Online (Sandbox Code Playgroud)

iphone url uitextfield ios

0
推荐指数
2
解决办法
8244
查看次数

标签 统计

ios ×3

iphone ×2

uitextfield ×2

nsstring ×1

null ×1

objective-c ×1

url ×1