Setting background to GroupTableViewBackgroundColor - xamarin.ios

I have a UIViewController in my Monotouch iPhone application and I want to set the background to what you have in a UITableViewStyle.Grouped. However when I use the code below it returns a black screen.
this.View.BackgroundColor = UIColor.GroupTableViewBackgroundColor; // Black screen
this.View.BackgroundColor = UIColor.Red; // Works
I call these in the ViewWillAppear method. If I comment out the GroupTable then the background gets set to Red. When I comment out the second line all I get is a black screen.
Does anyone know why this is? Can you not call UIColor.GroupTableViewBackgroundColor if your not in a UITableViewController?
Thanks
Mike

i have used this on my current project & it works fine i have xcode 4.0 & simulator 4.3
i have found on net that it is deprecated on ios 6
i have used like this
[self.tableview setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
just have look at this link is groupTableViewBackgroundColor deprecated on iOS 6?
for alternative you can find out same image as UItableview Grouped style background on internet.

Related

Not able to set status bar background in Xamarin.iOS

I need to change status bar UI, where background is black and text colour is white, in Xamarin.iOS (not forms).
For that I wanted to customise the status bar view, in have searched all I could on the internet and found below code working for majority of the people.
var statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
//tried with key statusBarWindow.statusBar as well.
statusBar.BackgroundColor = ...;
Above code crashes in Xamarin.iOS (tested on iPhone Xs Simulator).
Here is the log of the crash.
at (wrapper managed-to-native) ObjCRuntime.Messaging.xamarin_IntPtr_objc_msgSend_IntPtr(intptr,intptr,intptr)
at Foundation.NSObject.ValueForKey (Foundation.NSString key) [0x0001c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.2.1.12/src/Xamarin.iOS/Foundation/NSObject.g.cs:599
Could anyone help me with any hint as to why this code crashes in Xamarin.
I tried finding the cause on this GitHub thread https://github.com/mono/Embeddinator-4000/issues/597
But here also I am not able to get any clue of it.
Also, if there is any other way to customise the status bar I would like to drop this idea and go ahead with proposed one.
From what I know this works but usually when I use this I always make a check if the selector is available or not using RespondsToSelector:
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
statusBar.BackgroundColor = UIColor.White;
}
Also, do not forget to add the style to info.plist
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>
Update
Use the above code in AppDelegate.cs in the FinishedLaunching method.

Error on TextView with detection phone number IOS 9

I'm testing my app on an iPod Touch running iOS 9 (on iOS 8.4 it was working for other functions: FaceTime, copy to contacts, etc.). I have a textview with phone number detection and I receive the following error:
Warning: Attempt to present <_UIRotatingAlertController: 0x16250e00> on whose view is not in the window hierarchy!
Assertion failure in -[UITextView startInteractionWithLinkAtPoint:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.16/UITextView_LinkInteraction.m:377
Any fix to this?
Not a perfect solution but very simple and may help a desperate developer:
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange {
[[UIApplication sharedApplication] openURL:URL];
return NO;
}
You will lose the Copy, Open URL, Cancel popover on long press but you SHOULD at least be able to open url same as you would previously. In iOS 9, this still opens a browser window inside your app for standard URLs (which is nice).
This seems like an Apple bug (posted to radar already).
We were seeing very similar error when trying to open links in a modal view since Apple is trying to display a new modal alert view. Outside of modal view data detection worked just fine in iOS 9 for us.
This looks quite similar to a bug we recently had to fix for PSPDFKit where presenting sheets did not work when the rootViewController was already presenting another controller. (Is your rootViewController maybe not set?)
You can read the source code here. This might help you to figure out where the issue is for you:
https://gist.github.com/steipete/b00fc02aa9f1c66c11d0f996b1ba1265
And please dupe rdar://26295020 so this will get hopefully fixed in time for iOS 10. (The bug exists since iOS 8 and was first reported on iOS 8b5.)

Android UI alignment issues when supporting kitkat

I have been struggling to find a reliable solution to solve an issue from the past two weeks.
In our android app, we make use of a back ground image. There are some borders in this image in which we have to place different views.
The application needs to be supported from 4.0 to current latest version.
The issues I am facing are listed below.
The app when installed on devices with navigation bar looks perfect, but when run on devices without navigation bar the alignment is disturbed.
What did I try?
I tried checking if the OS version is 18 (4.3) and according to that created two layouts for each activity and installed.
The code is here
if (DEVICE_API_VERSION > 17) {
setContentView(R.layout.layoutwithnavigationbar);
} else {
setContentView(R.layout.layoutnonavigationbar);
}
But there are devices like samsung galaxy note II, which are upgradable to 4.4.2 and have no navigation bar.
Then I tried out the following proceedure.
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
boolean hasMenuKey = ViewConfiguration.get(mContext).hasPermanentMenuKey();
System.out.println("has back key . . . . "+hasBackKey);
System.out.println("has home key . . . . "+hasHomeKey);
System.out.println("has menu key . . . . " + hasMenuKey);
if(hasHomeKey || hasBackKey) {
setContentView(R.layout.layoutnonavigationbar);
} else {
setContentView(R.layout.layoutwithnavigationbar);
}
But again I had no luck.
In sony xperia sl which is 4.1.2 version of android, xhdpi, no navigation bar picks the layout perfectly, but in sony xperia m2, returns hasBackKey as true even if it is having a navigation bar and has no hardware menu buttons, and picks up layout with no navigation bar and layout looks ugly. Even tried few more things like resource id of navigation bar but in htc one s which has hardware buttons and no navigation bar, has a resource id for navigation bar. so it didn't work. I got the resource id as shown below.
int resourceId = resources.getIdentifier("navigation_bar_height",
"dimen", "android");
Did anyone have this problem?
Am I doing any thing silly or missing any thing?
What I am looking for?
1) My app should work from 4.0 to latest version.
2) If any device got navigation bar it can either be made completely transparent and use screen below that too, so that UI is not affected or any other better solution is also fine.
3) Want to know if there is any standard way to know if the device has a navigation bar or uses hardware buttons?
4) How can I make the navigation bar transparent in devices prior to Kitkat.
Note : App only is in landscape mode. Even tried transparent Navigation bar themes but they are only supported in kitkat. I am using values-hdpi,values-xhdpi, ect to get the UI aligned in different devices.
Please help me find a solution.
Finally after a lot of research I could not find a reliable solution. I don't know if it is the standard way of doing but it served my purpose. I used the answer in the stackoverflow question. get real size of screen
Got the display size of the screen as well using the following
DisplayMetrics displayMetrics = new DisplayMetrics();
d.getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
int displayWidth = displayMetrics.widthPixels;
if real width and display width are same it means device does not have a navigation bar, else device has a navigation bar. Accordingly I am setting appropriate layouts. I am concerned only with width as my app only runs in landscape mode.

UISplitViewController problems with IOS 5.1

I have a problem,
I am programming with Monotouch 5.2.8 for IOS 5.1.
But since the IOS 5.1 update my iPad configs the UISplitViewController so it is docked on the
left side instead of presented as a popover.
It works with IOS 5.0 but in 5.1 i got this problem.
Here is the source code for my UISplitViewController:
splitViewController = new UISplitViewController ();
splitViewController.WeakDelegate = detailViewController;
splitViewController.ViewControllers = new UIViewController[] {
navigationController,
detailViewController
};
From Apple's iOS 5.1 SDK release notes:
In 5.1 the UISplitViewController class adopts the sliding presentation
style when presenting the left view (previously only seen in Mail).
This style is used when presentation is initiated either by the
existing bar button item provided by the delegate methods or by a
swipe gesture within the right view. No additional API adoption is
required to obtain this behavior, and all existing API, including that
of the UIPopoverController instance provided by the delegate, will
continue to work as before. If the gesture cannot be supported in your
app, set the presentsWithGesture property of your split view
controller to NO to disable the gesture. However, disabling the
gesture is discouraged because its use preserves a consistent user
experience across all applications.
Here (login required).
UPDATE:
From what I understand on the above, we can kiss the automatic popover appearance of the master controller goodbye in iOS 5.1.
The only way I see is possible to keep the "old" appearance, is by implementing our own UIPopoverController and taking advantage of the ShouldHideViewController delegate method. Thankfully with MonoTouch, we have that method available as a property in the UISplitViewController class, making things a bit simpler.
I do get a strange behavior though. With iOS SDK 5.1 on my Mac and iOS 5.1 on my iPad; on the device, I get the "sliding" appearance, while on the simulator I get the "old", popover appearance. This is with MonoTouch 5.2.4, which is the latest stable version. Also, it does not contain a PresentsWithGesture property. I tried setting its value to false through MonoTouch.ObjCRuntime messaging, but no luck. The selector keeps returning true. So I cannot deactivate the swipe gesture.
Even tried creating my own UIPopoverController and assigning it as the master in the split controller to see what happens. Doesn't work because UIPopoverController is not a UIViewController...
Some useful info in this question, for ObjC.
Turns out you can disable the presentsWithGesture in the application delegate, but once the view controllers have been presented, there is no changing it.
I needed to disable the appearance of the left view controller during a login process, but turns out I can't enable it later.

UIWebView scrollTo hindered by a return to top

I have a ViewController with a UIWebView, in a Objective-c project for iPad.
When I add html (with loadHtmlString), I try to keep the scroll position it had before the loadHtml, but I cannot help and it returns to the top.
Here are the lines I use:
scrollPosition = [[webView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
[webView loadHTMLString:html baseURL:nil];
[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
I tested the value 'scrollY' at different locations in my code
and it stays at the value scrollPosition that I want, but when it ends up showing on the screen the WebView is always at the top (with the scrollY value then to 0).
Is there someone who could help me figure out why this happens?
I checked for hours the answers online, also on StackOverflow.
I tried different solutions (like adding in my webview the JavaScript "onclick="scroll(); return false;", but to no avail.
I tried to self-delegate the webView and update the scrollTo in webViewDidFinishLoad, but it seems that webViewDidFinishLoad is not called (the breakpoint is not reached) although I did add in .h in the interface and in the .m in ViewDidLoad the line: webView.delegate=self;
Thank you in advance for any help.
I realized that after recompiling, webViewDidFinishLoad was called after the html was updated, and that I could then scroll to the correct position.
For the self delegation I used in viewDidLoad, it looks so:
webview.delegate = self;
Before updating the html in the webView I calculate the scrolling position with the code:
scrollPosition = [[wbView stringByEvaluatingJavaScriptFromString: #"scrollY"] intValue];
Then, for moving back to this position once the webView has an updated html, I then use:
-(void) webViewDidFinishLoad:(UIWebView *)wbView {
[wbView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:#"window.scrollTo(0, %d);",scrollPosition]];
}
I found part of the solution through the post below, with the answer of Pawel:
How can I scroll programmatically to the bottom in a uiwebview

Resources