I m using Xamarin for iOS, Xamarin Studio v5.7.1
I having a small problem with the NavigationController.
I m pushing a ViewController programmatically like this:
ProfileViewController profileVC = ProfileViewController.ProfileViewControllerFromNib (this);
navController.PushViewController (profileVC, true)
And in the ViewDidLoad inside the ProfileViewController the NavigationController is null.
I thought to change the segue style to push like this smart guy said but with no success.
Any help will super welcome.
Thanks in advance.
Did you set the RootNavigationController of the window in your AppDelegate?
window.RootViewController = _rootNavigationController;
window.MakeKeyAndVisible ();
Related
I try to capture an image of all the elements inside my constaintLayout and then save it to the device.
I have done it on my iOS app, by capturing a UIView to an image with this simple line:
let theImage = self.myView.asImage()
Can I do something similar in Android Studio using Kotlin? Or is there any other layout/view better than constaintLayout that works like uiView in iOS?
Shameless copy and automatic to-kotlin conversion (litterally pasting the java code into a kotlin file in Android Studio) of https://stackoverflow.com/a/34272518/4265739
private fun createBitmapFromView(context: Context, view: View): Bitmap {
val displayMetrics = DisplayMetrics()
(context as Activity).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics)
view.setLayoutParams(LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT))
view.measure(displayMetrics.widthPixels, displayMetrics.heightPixels)
view.layout(0, 0, displayMetrics.widthPixels, displayMetrics.heightPixels)
view.buildDrawingCache()
val bitmap = Bitmap.createBitmap(view.getMeasuredWidth(), view.getMeasuredHeight(), Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
view.draw(canvas)
return bitmap
}
You can use the function above to create a bitmap containing the contents of the ConstraintLayout. In fact it should work for any View.
ConstraintLayout is the recommended layout to use in android. I cant tell if it works like iuView in IOS, but it is the Android way to do things.
I am new to the forum and to programming so hopefully I give you enough details and precise information needed to understand my question.
I am working with vaadin 7 in java EE web aplication and I have a layout problem/phanomena that I cannot explain and I could not find a solution on the net. Basically, when I start the server and test my application on localhost everything looks right. When I open a dialogue window and close it again, the layout of the site looks displaced. I could not find a pattern as to which click causes this effect. Sometimes it happens also when I only change a view. This is how it should look like and this is how it does look like after working in the application.
I looked through the devloper tool in the browser and noticed that in the working html, the attributes "top" and "left" are set for the gridlayout-slot. In the displaced layout these attributes are not set. Furthermore, it seems that the problem occurs more often in chrome. It does also happen in firefox but less often.
I use VerticalLayout, GridLayout and FormLayout.
Did you have similar experience? I am wondering how and when the html files are generated from the vaadin code to find out why they change and how I can fix it.
I am not sure which code exactly is causing the problem, so I am not sure what to post. If you have an idea where to look, I can add more code. Here is how the Dialog is set up:
public class Dialog extends Window implements ClickListener
public Dialog(CustomController controller, String title)
{
super(title);
setModal(true);
setStyleName("dialogWindow");
this.controller = controller;
setWidth("65.0%");
setHeight("90.0%");
// top level component properties
panLayout = new GridLayout();
panLayout.setWidth("100%");
panLayout.setHeight("100%");
buildPanToolbar();
panLayout.addComponent(panToolbar);
buildPanTop();
panLayout.addComponent(panTop);
buildPanTabs();
panLayout.addComponent(tabsheet);
panLayout.setComponentAlignment(tabsheet, Alignment.MIDDLE_CENTER);
panLayout.setRowExpandRatio(2, 1.0f);
tfThema.focus();
setContent(panLayout);
}
The buildSomething() functions are all a combination of GridLayout, FormLayout, HorizontalLayout and VerticalLayout. Below is the buildPanToolbar() function as an example
private void buildPanToolbar()
{
panToolbar = new HorizontalLayout();
panToolbar.setImmediate(false);
panToolbar.setWidth("100%");
panToolbar.setHeight("25px");
panToolbar.setMargin(false);
panToolbar.setSpacing(true);
panToolbar.setStyleName("toolbar");
HorizontalLayout panHelpToolbar = new HorizontalLayout();
panHelpToolbar.setImmediate(false);
panHelpToolbar.setWidth("-1px");
panHelpToolbar.setHeight("25px");
panHelpToolbar.setMargin(false);
panHelpToolbar.setSpacing(true);
panHelpToolbar.setStyleName("toolbarButtons");
panToolbar.addComponent(panHelpToolbar);
pbButton1 = new Button();
pbButton1.setCaption("Button1Text");
pbButton1.setStyleName(BaseTheme.BUTTON_LINK);
pbButton1.setImmediate(true);
pbButton1.setWidth("100px");
pbButton1.setHeight("-1px");
pbButton1.setIcon(new ThemeResource("../images/pic1.gif"));
pbButton1.addClickListener(controller);
panHelpToolbar.addComponent(pbButton1);
panHelpToolbar.setComponentAlignment(pbButton1, Alignment.MIDDLE_LEFT);
pbButton2= new Button();
pbButton2.setCaption("Button2 Text");
pbButton2.setImmediate(true);
pbButton2.setWidth("100%");
pbButton2.setHeight("-1px");
pbButton2.setStyleName(BaseTheme.BUTTON_LINK);
pbButton2.setIcon(new ThemeResource("../images/pic.gif"));
pbButton2.addClickListener(this);
panHelpToolbar.addComponent(pbButton2);
panHelpToolbar.setComponentAlignment(pbButton2, Alignment.MIDDLE_LEFT);
}
In UIWebView, if i call the function goback, the previous page will be present and execute its js code and set title on navigation bar. However, this do not work in wkwebview, it seems that wkwebview cache something and the js code is not executed.
I think the WKWebView is actually the more correct behaviour regarding the load event.
I have found that the pageshow event is better suited for code that needs to run on navigation changes.
Something like this should work in the WKWebView:
window.addEventListener('pageshow', function(event) {
// We were just shown again. Either initial load or due to
// navigation.
});
I was having a similar problem and the webpage was't being reloaded (on iOS 9.2 or higher versions) because it was showing a cached one, when calling goBack.
'Fixed' that clearing the cache data before calling goBack on the WKWebView. I still don't know if it is an iOS bug or Apple just decided to change the default behaviour from iOS 9.2.
In Objective-C would be something like this:
- (void)goBack {
[self cleanCacheWithCompletionHandler:^{
[super goBack];
}];
}
- (void)cleanCacheWithCompletionHandler:(void (^)(void))completionHandler {
if ([WKWebsiteDataStore class]) {
NSSet *websiteDataTypes = [NSSet setWithArray:#[ WKWebsiteDataTypeDiskCache,
WKWebsiteDataTypeMemoryCache]];
NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:completionHandler];
} else {
completionHandler();
}
}
Note that I subclassed WKWebView in the sample code and that you have to check the availability of WKWebsiteDataStore as it is new to iOS 9.
It seems that UIPageViewController is holding the initial content view controller forever.
For example:
DataViewController *startingViewController = [self.modelController viewControllerAtIndex:0 storyboard:self.storyboard];
NSArray *viewControllers = #[startingViewController];
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:NULL];
self.pageViewController.dataSource = self.modelController;
The startingViewController is never released until the pageViewController itself it released.
To reproduce this bug, just create a new project in XCode using the Page-Based Application template. And add 3 lines of code into DataViewController.m
#property NSInteger debugIndex; // file scope
NSLog(#"DataViewController[%d] created", self.debugIndex); // in viewDidLoad
NSLog(#"DataViewController[%d] dealloc", self.debugIndex); // in dealloc
And when you scroll the demo App in vertical orientation, you'll get logs like this:
DataViewController[0] created
DataViewController[1] created
DataViewController[2] created
DataViewController[1] dealloc
DataViewController[3] created
DataViewController[2] dealloc
DataViewController[4] created
DataViewController[3] dealloc
DataViewController[5] created
DataViewController[4] dealloc
DataViewController[6] created
DataViewController[5] dealloc
DataViewController[0] is never deallocated.
Any ideas about this?
Thanks!
Are you using transitionStyle UIPageViewControllerTransitionStyleScroll? I encountered the same or a similar problem which seemed to disappear when using page curl animations instead.
The problem was compounded for me because I was allowing a UISliderBar to set the position in the content. So on change of the UISliderBar, I was calling setViewControllers:direction:animated:completion: which caused more and more view controller references to get "stuck" in my UIPageViewController.
I am also using ARC. I have not found an acceptable way to force the UIPageViewController to let go of the extra view controller references. I will probably either end up using the page curl transition or implementing my own UIPageViewController equivalent using a UIScrollView with paging enabled so I can manage my own view controller cache instead of relying on UIPageViewController's broken view controller management.
I'm not sure you still got the problem, but I had the same problem and I found the solution.
I don't know the reason, but it works.
I'm setting the first viewController right after addSubview, rather than before addChlidViewController.
-(void)settingPageViewController{
if (!self.pageViewController) {
self.pageViewController = [[UIPageViewController alloc]initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];
self.pageViewController.delegate = self;
self.pageViewController.dataSource = self;
[self addChildViewController:self.pageViewController];
[self.pageViewController didMoveToParentViewController:self];
[self.containerView addSubview:self.pageViewController.view];
[self.pageViewController setViewControllers:#[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
}
and the first viewController will dealloc in the right time.
also, I found if call
[self.pageViewController setViewControllers:#[[self viewcontrollerAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:^(BOOL finished){
NSLog(#"finished : %d",finished);
}];
before addSubView and the completion block will not call.
and I reckon this block is the reason why the first viewController didn't dealloc.
I'll go find out why it didn't callback, and improve the answer~
cheers
After a few attempts to figure out what was happening on a similar issue, I noticed that in my project there were 2 reasons that caused a retain problem and resulted in having a UIPageViewController being forever retained.
1) there was a circular reference between the UIPageViewController and the UIViewcontroller that was presented (this was fixed by changing the properties to weak from strong in both classes)
2) and the main fix consisted in changing
[self setViewControllers:#[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
to
__weak __typeof__(self) weakSelf = self;
[weakSelf setViewControllers:#[initialDetailsViewController] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
I hope this helps someone
same problem here
i resolved it by keeping my initial viewController in the variable
and instead of creating the same vc on particular pageIndex i just reuse it
I had same problem and solved the following:
[startingViewController release]; where the end point of initialization.
then the first ViewController will be deallocated.
I've updated my iOS SDK to version 6. After that I've compiled my app (works fine in iOS 4 & iOS 5) but now the location services doesn't work. My delegate isn't receiving any update and the upper location arrow is not appearing... I'm starting the service as the usual way:
[locationManager startUpdatingLocation];
My project is non ARC.
What is happening? This is driving me crazy...
Thanks in advance.
Make sure you have a CFBundleDisplayName in your project's .plist file. Adding that key fixed it for me.
Just set the property pausesLocationUpdatesAutomatically of Location Manager to NO. This is a new feature of IOS 6 that disable Location Updates when application runs in background. The default value of this property is YES.
This is a change in iOS6:
You need to implement locationManager:didUpdateLocations: instead of locationManager:didUpdateToLocation:fromLocation to be notified when the location is updated.
You should also read the documentation about startUpdatingLocation.
In my case, I had the location manager under a different class and I was calling this class from the main controller. This was not working and the didUpdateLocations was not called.
//
// LocationServices.h
//
#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>
#interface LocationServices : NSObject <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
}
#property (nonatomic, retain) CLLocationManager *locationManager;
- (void)startLocationServices;
#end
// LocationServices.m
#import "LocationServices.h"
#implementation LocationServices
#synthesize locationManager, currentLocation;
- (void)startLocationServices {
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.pausesLocationUpdatesAutomatically = NO;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
if ([CLLocationManager locationServicesEnabled]) {
[locationManager startUpdatingLocation];
} else {
NSLog(#"Location services is not enabled");
}
}
////////////////////////////////////////////////
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations {
CLLocation* location = [locations lastObject];
NSLog(#"Updated: latitude %+.6f, longitude %+.6f\n",
location.coordinate.latitude,
location.coordinate.longitude);
}
#end
// Main controller
- (void)viewDidLoad {
[super viewDidLoad];
.....
LocationServices *locationSerices = [[LocationServices alloc]init];
[locationSerices startLocationServices];
......
}
The above code does not work. Why? I do not know ....you can easily lose interest when you spend so much time trying to do a thing that is supposed to be simple. iOS is very complicated and unfriendly programming environment. There are many ways to do one thing, only one works, you cannot mix and match without introducing a problem. You have to do everything by the book or you or you get nothing. Not even a hint that you did something wrong ... frustrating ...
Instead when I implemented
locationManager:(CLLocationManager *)manager didUpdateLocations:
in the main controller everything worked fine
The issue seems to be resolved in IOS 6.1 Beta2 - http://www.youtube.com/watch?v=aFZR0eMUV74
setting CFBundleDisplayName solved the problem for me. Same thing location update was never called, just set the info.plist parameter and it start working.
I've tried everything in plist files, cleans, rebuilds, new targets, configurations, etc, etc, etc. Nothing worked. But FINALLY I've fixed it. I had to create a new Xcode 4.5 project from scratch, reconfigure it, add file by file and framework by framework manually. It seems that my old XCode project had something internally incompatible with last XCode. I write this here because maybe it can save someone's next 10 hours of work.
Am I being too simplistic here? Under Privacy, Locations looks the same as it did in previous issues.What's all the fuss about?