UIButton Enable/Disable No working - ios

UIButton enable not working after Xcode Update to Xcode 5.0.1.
self.btn.enabled = NO;
self.btn.hidden = NO;
Please suggest.

You should probably check the following in your project :
Checklist
Make sure that the button btn is connected to the relevant button in the xib in the Interface Builder.
Check whether the method where you put the two lines self.btn.enabled = NO; and self.btn.hidden = NO; gets called or not.
Try using self.btn.userInteractionEnabled = NO;.
Maybe, you're re-setting the enabled property to YES somewhere later in the code.
These points were all I could think of, tell me if it resolves your issue.

If you are using Xib file to build interface. Then make sure that IBOutlet is set for self.btn? If not, Then set IBOutlet for that. If you post your full source code for self.btn, Then i can help you more.

Related

Disable Pull-To-Refresh

I have a static group of cells, a few groups actually, and for some reason the pull to refresh function is enabled, I can't figure out where, at least in Xcode Interface builder an option is to disable that. I assume I'll have to do it programmatically.
Does anyone know how this needs to be done in Swift?
If you're using UITableViewController, it should be something as simple as
self.refreshControl = nil
In storyboard, go to your Attributes Inspector for your View Controller and disable it there where it says 'Refreshing':
For swift 4 you can using
self.yourTableView.refreshControl = nil

How to update constraint in code using objective c

In my xib file, I have a constraint for height for the label in my xib file.
And in my objective c, I tried to change it using
self.heightConstraint.constant = newHeight;
But nothing is changed when I run it in simulator. I have used debugger and make sure that line is executed. And in Spark tool, I see the label height is the old height.
How can I adjust the height dynamically?
Updated:
I have changed my code to add a nil check.
if (self.heightConstraint != nil) {
self.heightConstraint.constant = newHeight;
}
My code still get executed, but nothing get changed.
There's nothing wrong with your code itself:
self.heightConstraint.constant = newHeight;
But the reason this changes nothing in your interface, even though it is being executed, is that self.heightConstraint is not a reference to a constraint in your interface. (It is probably nil.)
I agree with Matt. The likely reason your code isn't working is that you have a broken outlet link. In general, when code that tries to do something with an outlet or action doesn't work, the most likely cause is a broken outlet or action connection.
Rule of thumb: When debugging stereo or computer hardware, check the cables.
Corollary for for iOS or Mac OS apps in Xcode: When debugging UI code, check your IBOutlet and IBAction connections.
At what part of the view controller lifecycle are you changing the constraints? You may need to call setNeedsLayout on the parent view.

Getting URL of UIWebView

I'm sort of new to Xcode, so forgive me in advance for any obvious wrong things that I might write.
I'm trying to write something a bit simple using the UIWebView. I've already made it load upon the app's loading, but I can't seem to do anything else. What I want to do next is to make a button appear/disappear depending on the current URL. This is what I used to (try to) get the current URL:
NSString *currentURL = viewWeb.request.URL.absoluteString;
(I'm using this code in the ViewController.h file)
When I made the outlet (Ctrl+dragging), I named it viewWeb and I also went and labeled it viewWeb. But it doesn't seem to work and I don't know why.
Also, please don't just give me some code without explaining, because this is a bit frustrating and I want to understand it.
EDIT: Thanks, but I'm not looking for help on the disappearing button just yet (by the way, viewWeb is my UIWebView, not the button). I need help to detect an URL change to make the button disappear. Is there a webViewDidLoad or something similar? viewDidLoad isn't for this.
In the ViewController.h File, you only declare the property, like this:
#property (strong,nonatomic) NSString *currentURL;
Then you can set the value in the ViewController.m file.
maybe in the -viewDidLoad method in the ViewController.m file like this:
_currentURL = viewWeb.request.URL.absoluteString;
You can set the property of hidden or not of the button to show it selectively based on the url.
// URLString contains the URL based on which you would like to show/hide the button
if ([currentURL isEqualToString:URLString]) {
viewWeb.hidden = NO;
}
else {
viewWeb.hidden = YES;
}

Is ios7 UITableViewController's Clear on Appearance broken (from Storyboard)?

Using Storyboards in XCode5 for iOS7, I unchecked the "Clear on Appearance" checkbox for a UITableViewController. Using the version editor, I could see that the actual text in the file reacted accordingly (btw, is there a better way to see "source" of the storyboard?). But when I added
-(void) viewDidLoad {
[super viewDidLoad];
NSLog(#"clear on appear %d", self.clearsSelectionOnViewWillAppear);
}
It always showed as 1 (YES). Regardless of on or off in the storyboard. To get the desired affect, I had to add:
self.clearsSelectionOnViewWillAppear= NO;
to that method. Did I misunderstand the way this was supposed to work? Or is it broken?
Yes, seems like it is broken.
This works on viewDidLoad:
self.clearsSelectionOnViewWillAppear = NO;
Yes, looks like a bug, at least as of iOS 9.3. You can use IB's User Defined Runtime Attributes if you don't want to fix it in code:

Can I connect xib object to any viewController?

I know it is possible to connect an object in a XiB file (i.e button) and connect it to any viewController. I am also able to go to that viewController and programmatically set properties to that object(everything autocompletes fine, it recognizes the object properties) However, when I run the app, the button is unchanged, what gives?
Is there something I'm missing? Is there an additional step that I need to do when using a ViewController that is not the .m file related to the XIB?
Here's part of the code... I don't get any errors!
user.default_sales_rep_id = 2;
if (user.default_sales_rep_id > 0) {
buttonMask.backgroundColor = [UIColor blackColor];
}
You are most likely setting the properties on the button too early. Since you don't specify in your question where this code is located, it's hard to say but I'd guess if you put your code in awakeFromNib it would work.
- (void)awakeFromNib {
[super awakeFromNib];
//code here
}
Any changes to your view that differ from your XIB should be done in this method as it is called after the view is set up from the XIB.
Are you certain you are calling [[UIButton alloc] init] before you attempt manipulating it? I assume you have the button already as an IBOutlet, but if I recall, if you wish to make custom changes to the button, you must still do this.

Resources