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

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:

Related

Removing scrollbars in iOS for WKWebViewEngine

I have a Cordova app that is since recently using WKWebViewEngine and I noticed horizontal and vertical scrollbars appearing since switching.
I researched and the issue is documented at:
https://issues.apache.org/jira/browse/CB-10123
A CSS fix does not work but there is apparently a fix with using:
self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;
The question is where do I add this fix? I checked in CDVWKWebViewEngine.m but am not sure where to add it.
In case it helps, in a pure iOS app those 2 lines of code :
self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;
would typically be placed within the view controller viewDidLoad function.
I don't know the details of Cordova, but you should find your view's view controller (could be CDVViewcontroller in CDVViewcontroller.m (?)) and add those lines at the end of the viewDidLoad method.
Alternatively (and certainly cleaner), you could subclass CDVViewcontroller into your own ViewController class and override viewDidLoad like this
- (void)viewDidLoad {
[super viewDidLoad];
self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO
}
then find a way to force Cordova to use your view controller class instead of its own.
Take care, in the codes I've read, the web view property is called webView and not wkWebView, so you might need to change that in your two lines.

Updating Constraints programmatically iOS

I need to update a constraint programmatically in my project to adjust a view's height accordingly (based on different subviews). I've made outlet of the constraint in my controller but facing an issue.
when I try to update this for the first time (in viewDidLoad or viewWillAppear method), it's not updated. and if i update it afterwards (because of some rotation etc), then it is done correctly. Kindly tell me why this is happening and what is the right way/place to do this? (As i feel that the constraint is updated somewhere again after my updation in viewWillAppear/DidLoad).
I tried view.layoutIfNeeded as well but it didn't help. I guess it has something to do with viewDidLoad and other viewController delegate methods
P.S. I'm also using size classes in my project but I think it has nothing to do with that as it's working in some cases.
Updating constraints may not work in viewWillAppear.
It will, however, work in viewDidAppear.
There are other places you may overwrite, such as: (using static BOOL shouldRefreshView = NO; for the first time)
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if(shouldRefreshView) {
shouldRefreshView = NO;
[self.view layoutIfNeeded];
}
}

UIImageView outlet is still nil after viewDidLoad only on iOS7

I have an static UITableView with grouped cells, and an outlet for an UIImageView in the first group and I try to set its image on viewDidLoad like this
- (void)viewDidLoad {
[super viewDidLoad];
self.productImageView.image = [UIImage imageNamed:#"someImage"];
}
I found the productImageView (UIImageView) is nil but only on iOS7 (7.1.2), as far as I knew, it shouldn't be nil after viewDidLoad
Can anyone tell me why this is the only outlet is not loading from my storyboard?
Moving your code to the viewWillAppear will likely fix your issue, but that's not really the optimal solution. What if you add a call to [self.tableView reloadData]; before you set the image to make sure that the tableView is initialized?
Well, I found the reason
I made the ViewController in a different storyboard, Xcode 6, with the new format for storyboards and different devices, but actually, our project is as old as Xcode 5 and we still use those storyboards, when I made copy & paste of the ViewController from the new storyboard to the old one, it should work because we are used to this, and it does with iOS8, but I noticed the view is shown like this in the view inspector
http://i.stack.imgur.com/ticT5.png (can't post images yet)
Seems like the image and its constraints are disabled and deleting the element, adding a new one seems to solve the problem for iOS7 and still work with iOS8

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.

UIButton Enable/Disable No working

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.

Resources