viewWillLayoutSubviews is being called recursively - uiviewcontroller

I have view controller presented as a form sheet, in which there will be a table view with custom cell having a label on left and a textfield on right.
The form sheet size (height) will be dynamically increased based on the selection done from the options that will be given in the tableview.
So, for initial configuration, i use this
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
CGRect newBoundsForSuperView=CGRectMake(0, 0, max_view_width,max_view_height);
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.00")==YES)
{
self.view.superview.bounds=newBoundsForSuperView;
self.view.superview.center=self.view.window.center;
}
}
When I tap on the textfield, the viewWillLayoutSubviews is getting called infinite times and the application is getting freezed.
Can anyone point out what and/or where the problem is exactly ?
BTW, the issue is only in iOS 8.

I believe your problem is related to setting self.view.superview.bounds which is causing the superview to call viewWillLayoutSubviews in a recursive manor.
Look into setting the preferredContentSize attribute of the view controller for iOS7+.

Related

Polymer - cloneNode including __data

I am using the library dragula for doing some drag & drop stuff.
Dragula internally uses cloneNode(true) to create a copy of the dragged element that will be appended to the body to show the preview image while dragging.
Unfortunately, if dragging a polymer element, the bound data get's not cloned. By consequence the contents of the dragged element (e.g. <div>[[someString]]</div>) are empty.
Is there a solution for this?
I actually do not need the data to be bound for my element, it is just a "read-only" element that displays some data that does not change after being initialized. Is there maybe a way to somehow "resolve" the strings to the html without being bound anymore?
Thank you already!
Found a solution myself. You have to override the cloneNode method inside the polymer class:
cloneNode(deep) {
let cloned = super.cloneNode(deep);
for (let prop in MyClass.properties) {
cloned[prop] = this[prop];
}
return cloned;
}

How to refresh particular div in the html

I am getting a problem to reflect the value in the view, I don't want to load the complete page because its very costly to load the page,
I have two controllers(controller1 and controller2), one service(service1) and two views(modalwindow.html and product.html).
The scenario is:
1.User is on product.html(contains multiple accordions) and user explicitly close all the accordions.
2.User clicked on icon which opened modal window, since it's opened the modal window it's not going to change the URL on the address bar.
3.Modal window(Modalwindow.html ) has the link of show product, since the product page is the active page(show product is the accordion which closed by user explicitly) on the browser.
on the click of link, appropriate accordion should be open on the product.html
I am communicating between modal window controller (controller2.js) and product page(controller1.js) through service (service.js), I am calling controller2
how to fix this issue without loading a complete page
Assuming the modal closes when a product is selected, it can return the value to the calling controller. Then it opens the specified accordion.
I fiddled around in your fiddle. You are mixing two ways of showing your categories in the fiddle: an accordion value, and two boolean values (categoryAccordion, productAccordion). I moved to using one way and it seems to work with the eventCallback. Also, you checked wrongly for your 'args' in the eventCallback. You're passing it back as an array, so get the value out of the array first.
Also, you checked wrongly for your 'args' in the eventCallback.`
if (args[0] == 'Product') {
$scope.productAccordion = true;
$scope.categoryAccordion = false;
} else {
$scope.productAccordion = false;
$scope.categoryAccordion = true;
}
See fiddle.
Should it not be working in your real code, it might have something to do with the following SO question.

Android ListView binding programmatically

There are many examples of doing this in axml, but I would like to have a complete binding using code behind. To be honest, I would like to have NO axml, but seems like creating all the controls programmatically is a nightmare.
I first tried the suggestions at:
MvxListView create binding for template layout from code
I have my list binding from code-behind, and I get six rows (so source binding is working); but the cells itself does not bind.
Then at the following url:
Odd issue with MvvmCross, MvxListViewItem on Android
Stuart has the following comment: Have looked through. In this case, I don't think you want to use DelayBind. DelayBind is used to delay the binding action until next time the DataContext is set. In Android's MvxAdapter/MvxListItemView case, the DataContext is passed in the ctor - so DataContext isn't set again until the cell is reused. (This is different to iOS MvxTableDataSource).
So in essence, the only example I see shows DelayBind, which shouldn't work.
Can someone please show me some examples... thanks in advance.
Added reply to Comments:
Cheesebaron, first of all, a huge thank you and respect for all your contributions;
Now, why not use axml? Well, as programmers, we all have our own preferences and way of doing stuff - I guess I am old school where we didn't have any gui designer (not really true).
Real reasons:
Common Style: I have a setup where Core has all the style details, including what all the colors would be. My idea is, each platform would get the style details from core and update accordingly. It's easy for me to create controls with the correct style this way.
Copy-Paste across platform (which then I can even have as linked files if I wanted). For example, I have a login screen with web-like verification, where a red error text appears under a control; overall on that screen I have around 10 items that needs binding. I have already got iOS version working - so starting on Droid, I copied the whole binding section from ios, and it worked perfectly. So, the whole binding, I can make it same across all platform... Any possible error in my way will stop at building, which I think is a major advantage over axml binding. Even the control creation is extremely similar, where I have helpers with same method name.
Ofcourse I understand all the additional layout that has to be handled; to be honest, it's not that bad if one really think it through; I have created a StackPanel for Droid which is based on WP - that internally handles all the layouts for child views; so for LinearLayout, all I do is setup some custom parameters, and let my panel deal with it. Relative is a different story; so far, I have only one screen that's relative, and I can even make it Linear to reduce my additional layout code.
So, from my humble point of view, for my style, code-behind creation allows me to completely copy all my bindings (I do have some custom binding factories to allow that), copy all my control create lines; then only adding those controls to the view is the only part that is different (then again, droid and WP are almost identical). So there is no way I can miss something on one platform and all are forced to be the same. It also allows me to change all the styles for every platform just by changing the core. Finally, any binding error is detected during compile - and I love that.
My original question wasn't about NOT using axml... it was on how to use MvxListView where all the binding is done in code-behind; as I have explained, I got the list binding, but not the item/cell binding working.
Thanks again in advance.
Here is part of my LoginScreen from droid; I think it's acceptable amount of code for being without axml file.
//======================================================================================================
// create and add all controls
//======================================================================================================
var usernameEntry = ControlHelper.GetUITextFieldCustom(this, "Username.", maxLength: 20);
var usernameError = AddErrorLabel<UserAuthorization, string>(vm => ViewModel.Authorization.Username);
var passwordEntry = ControlHelper.GetUITextFieldCustom(this, "Password.", maxLength: 40, secureTextEntry: true);
var passwordError = AddErrorLabel<UserAuthorization, string>(vm => ViewModel.Authorization.Password);
var loginButton = ControlHelper.GetUIButtonMain(this);
var rememberMe = new UISwitch(this);
var joinLink = ControlHelper.GetUIButtonHyperLink(this, textAlignment: UITextAlignment.Center);
var copyRightText = ControlHelper.GetUILabel(this, textAlignment: UITextAlignment.Center);
var copyRightSite = ControlHelper.GetUIButtonHyperLink(this, textAlignment: UITextAlignment.Center);
var layout = new StackPanel(this, Orientation.Vertical)
{
Spacing = 15,
SubViews = new View[]
{
ControlHelper.GetUIImageView(this, Resource.Drawable.logo),
usernameEntry,
usernameError,
passwordEntry,
passwordError,
loginButton,
rememberMe,
joinLink,
ControlHelper.GetSpacer(this, ViewGroup.LayoutParams.MatchParent, weight: 2),
copyRightText,
copyRightSite
}
};
I just came across a similar situation myself using Mvx4.
The first link you mentioned had it almost correct AND when you combine it from Staurts comment in the second link and just remove the surrounding DelayBind call, everything should work out ok -
public class CustomListItemView
: MvxListItemView
{
public MvxListItemView(Context context,
IMvxLayoutInflater layoutInflater,
object dataContext,
int templateId)
: base(context, layoutInflater, dataContext, templateId)
{
var control = this.FindViewById<TextView>(Resource.Id.list_complex_title);
var set = this.CreateBindingSet<CustomListViewItem, YourThing>();
set.Bind(control).To(vm => vm.Title);
set.Apply();
}
}
p.s. I have asked for an Edit to the original link to help others.

Flash AS3 Creating components on stage via Button

Sorry for my complicated questioning ;)
I've created several components on my stage (Slider, TextLabel, CheckBox, ...) with the addChild(...) method. Now, if the user needs one Slider component more (for another input), I want to give him a button "addButton" (already on stage) with an CLICK addEventListener. The function which is fired in the addEventListener should create a new Slider component on stage, e.g.
addButton.addEventListener(MouseEvent.CLICK,addSlider("slid1",20,160,250,0,250,30));
The problem is to pass the parameters to the function, i need to set the new Slider to several basic values, like position, width, minimum, maximum and so on....
Can this be achieved in this way?
thx,
edwin
There are several ways you can do this. The simplest way is to call your function inside a mouse event handler:
addButton.addEventListener(MouseEvent.CLICK, addSliderHandler);
function addSliderHandler(e:MouseEvent):void {
{
addSlider("slid1",20,160,250,0,250,30);
}
EDIT (to answer your comment question):
To position your new component according to existing components, you can keep a variable reference to the position in the script and pass this as a parameter. For instance, suppose you want the first generated slider to be at y:160, and every slider to be 40px more than this, change the script to this:
var sliderY:int = 160;
addButton.addEventListener(MouseEvent.CLICK, addSliderHandler);
function addSliderHandler(e:MouseEvent):void {
{
addSlider("slid1",20,sliderY,250,0,250,30);//Pass sliderY instead of literal number
sliderY += 40;//Add 40 to sliderY
}
Now, every time you use this function to create a button it will be positioned at y = sliderY, then it will add 40 to sliderY....so the first one generated will be at 160, the next at 200, the next at 240 etc.
Hope this helps!

SmartGWT TabSet.destroy() and recreation

I was having ID collision of tab IDs when trying to recreate the same TabSet.
My case is the following : I have 3 Tabs in general, then some action creates a 4th one, some action happens in this 4th tab which is then closed, and I need to relaunch my app and redraw again the 3 general Tabs fetching new info from the database. Everything was working well, except this warning of collision which was not a blocking one anyway.
In order to clean it, I followed Isomorphic's advice from this thread
and tried destroying the TabSet in order to recreate it.
I do:
if (myTabSet != null) {
myTabSet.destroy();
}
myTabSet = new TabSet();
// setting TabSet properties
// creating Tabs and adding them to the TabSet
I noticed, however, in debug, that the TabSet is not being desroyed completely, just some of its properties, and that a new ID is being given to it. As a result, there are no more warnings, the tabs are created, but they're not populated.
My question is : why the TabSet is not becoming null upon destruction, and how can I recreate it with no collision of IDs?
Thanks in advance
I used to have the same problem and fixed it with:
myTabSet.addCloseClickHandler(new CloseClickHandler() {
#Override
public void onCloseClick(TabCloseClickEvent event) {
event.getTab().getPane().destroy();
}
});
Apparently the tabset is not completely destroyed unless you destroy its pane.
Maybe it will work for you !