Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7728395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:42:23+00:00 2026-06-01T05:42:23+00:00

My app checks if an NSString is empty when it launches, like this: if

  • 0

My app checks if an NSString is empty when it launches, like this:

if ([checkfieldstring1 isEqualToString:@""]) {

    checkboxButton.hidden = YES;
}
else {

    checkboxbutton.hidden = NO;
}

However, when there is an empty string, the button is not being hidden. I know this method works when I hook it up as an IBAction to a button, but not on ViewDidLoad…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T05:42:24+00:00Added an answer on June 1, 2026 at 5:42 am

    Checking for an empty string when the view is about to load needs to check for a nil string or an empty string as the string may not have been set up yet.

    if (checkfieldstring1 == nil || [checkfieldstring1 length] == 0) {
        checkboxButton.hidden = YES;
    } else {
        checkboxButton.hidden = NO;
    }
    

    Or, if you do as I do and have this in a set of common macros that I add to a project:

    static inline BOOL isEmpty(id thing)) {
        return thing == nil
            || ([thing respondsToSelector:@selector(length)]
            && [(NSData *)thing length] == 0)
            || ([thing respondsToSelector:@selector(count)]
            && [(NSArray *)thing count] == 0);
    }
    

    Courtesy of Wil Shipley http://www.wilshipley.com/blog/2005/10/pimp-my-code-interlude-free-code.html

    you could just check with:

    if(isEmpty(checkfieldstring1) {
        checkboxButton.hidden = YES;
    } else {
        checkboxButton.hidden = NO;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winforms app that checks user credentials as it starts. If autharization
I'm developing an app that checks several conditions during an incoming phone call. The
I am wanting to create a VB.Net app that checks a database and then
I would like to do two things within my Android app : Check if
In a WPF app I'd like to check if a return of a LINQ
I have an app that checks for a file upon load from the appDelegate's
I'm working on an app that checks an array to see if it contains
I have an app that works fine in iOS 4, but there is a
I would like to check reachability before/when a webView is shown in my app.
Ok so I am trying to get this app to show network error alert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.