Touch Up Inside event not working after rotation of tab bar - uitabbarcontroller

I have a button in one of view controller of tab bar controller. All set up in storyboard. I registered action method like this
- (IBAction)buttonPressed:(id)sender {
NSLog(#"Button pressed");
}
The thing is that once I make left and top constraints (to force it stay in the right upper corner) touch up inside event stops working after I change rotation. So just open app in portrait mode - method is working. Change to landscape and I cannot tap button suddenly.
I've recreated problem in this easy example project.
Many thanks.

Just put the following code in you TabBarViewController class.
- (void)viewDidLayoutSubviews
{
// fix for iOS7 bug in UITabBarController
self.selectedViewController.view.superview.frame = self.view.bounds;
}

Recently I noticed same bug in my application. First I tried Slavco Petkovski method. But this caused me another bug with rotating and getting right bounds and frame, so I kept searching.
I found another solution for this problem, mainly setting autoresizing mask of view controller's view in xib. But since arrows in inspector in my Xcode (version 5.0.1) are inactive and you can't set them, you have to open xib file in text editor find autoresizingMask property for main view and change it like this:
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
EDIT:
Alternatively you can do this in your view controller's code - same result as in changes in xcode:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

Related

Dynamic theme color at run time jetpack compose

I'm new to Jetpack Compose, so I'm struggling to implement a feature which is dynamic colors (and font, size,... but I think they are the same so I'll just focus on color) at run time from backend. I'll let the app the some default colors, and a whole default splash screen just to load the colors setting from the backend. In case the API request failed, it would use the last succeeded requested colors or just the default color.
Tutorials I found round the internet was just about changing the dark/light theme at run time, not changing a specific color in the color pack. In those tutorials, the color is defined in Colors.kt file which is not a composable or class or object, ...
I imagine the color within lightColors or darkColors would be something like this.
return lightColors(
primary = Color(android.graphics.Color.parseColor("#" + dynamicColorMap["One"])),
...
}
And when dynamicColorMap changes in the splashscreen, all screen later will have reference to the new value, but I don't know how to update its variable outside of a composable.
I thought of using DB to store the colors, but getting the data from DB is async, so it cannot be query in the default Colors.kt like var colorOne = DBManager.getColor("One"), I can run the async task in my splash screen before changing to the next screen but then the problem again is how to have a global state that my theme composable wrapper can have access to on every screen?
I just don't know where to start for these case.
Thank you for your time
EDIT:
I currently having the project structured in MVVM. For now, only one activity (MainActivity) is present, and inside that activity, the splash screen component or home screen or login screen,... are being navigated. So is it a good practice to create a viewmodel for the mainactivity screen, that can holds the color state for the theme?
Thanks #Maciej Ciemiega for the suggestion. I ended up structure my code like that.
In my MainActivity.kt I create a viewmodel for it.
val mainActivityViewModel by viewModels<MainActivityViewModel>()
MyTheme(mainActivityViewModel = mainActivityViewModel) {
initNavigationController(navController)
Surface(color = MaterialTheme.colors.background) {
if (mainActivityViewModel.appSettingsState.value.appSettings.colorsMapLight.size != 0
&& mainActivityViewModel.appSettingsState.value.appSettings.colorsMapDark.size != 0) {
navController.navigate(NavigationDestinations.homeScreen)
}
}
}
my initNavigationController function shows the splashscreen first. But it doesn't do anything. The getting app settings configuration is called in MyTheme composable via the mainActivityViewModel, and MyTheme will use the state from the viewmodel to define the theme, and the navController.navigate is based on the state as you guys can see in the if above.
I don't know if this is a good practice or not, or when my app grows it would be a mess or not, but at least it works for me. I tried with font styles too and it works like a charm.

myComboBox->Dismiss(); not working under wxEVT_TEXT and wxEVT_COMBOBOX_DROPDOWN

My objective:
During wxEVT_COMBOBOX_DROPDOWN load up a choiceDialog and set the choice as combo box value and finally close the combobox using dismiss().
What I tried:
void Class_Scheduler_FNFrame::myComboBoxDropdown(wxCommandEvent& event)
{
SingleChoiceDialog1->ShowModal();
int i = SingleChoiceDialog1->GetSelection();
myComboBox->SetValue(wxString::Format(("%s"), myWxStringArray[i]));
myComboBox->Dismiss();
}
The value got changed but the dismiss(); is not working.
So I tried moving dismiss to wxEVT_TEXT.
void Class_Scheduler_FNFrame::myComboBoxTextUpdated(wxCommandEvent& event)
{
testLabel->SetLabel("This should have worked");
myComboBox->Dismiss();
}
Dismiss() is not working in wxEVT_TEXT as well. But when I type onto the combobox, after triggering wxEVT_COMBOBOX_DROPDOWN, dismiss() is working through wxEVT_TEXT .
Help!
You're trying to do something rather weird: have you ever seen a modal dialog show while the combobox dropdown is opened? I haven't and, generally speaking, there should be only a single modal element shown at each moment.
So why do you have this objective? What is the point of showing the dialog whenever a combobox is opened? It doesn't even seem like you're using it like a combobox at all. Maybe you're actually after some kind of wxFilePickerCtrl-like behaviour, i.e. a small button showing the dialog near a text control? Or maybe you want to use wxComboCtrl instead?
Anyhow, it should be possible to do what you want by postponing showing the dialog using CallAfter(), but I'm almost sure that you actually don't want to do that anyhow.

How to allow a button that creates a new object in SwiftUI from not making an object on reload?

So I'm making a button for a "New Note" in Swift UI similar to the Apple Notes app.
Right now my "New Button" is a "Navigation Link" like so:
NavigationLink(
destination: EditorView(makeNewNote())
) {
Text("New")
}
Unfortunately—this triggers my app to create a new note every time the view loaded. :(
:/
I've been looking for a way to initate a segue on button push but I'm not finding success on this yet.
When I tried a modal—I found myself having the same problem
Button("New") {
self.isNew = true
}.sheet(isPresented: $isNew, content: {
EditorView(makeNewNote())
})
I'm wondering what the best way to approach this would be.
Having no success :(
Edit:
I referred to this and the documentation but I haven’t found a way to segue via a button push which would be ideal. (The function dosent get triggered in the closure :)
https://www.hackingwithswift.com/quick-start/swiftui/how-to-push-a-new-view-onto-a-
Also...if you were curious what makeNewButton() does—it basically inserts a new Core Data object into my app’s managed context.
I'm not entirely sure, but it kinda sounds like to me your problem lies in your model. Because each time your View loads it calls the makeNewButton() function right?
Maybe you can fix the problem by displaying the "new note" view and having an extra "Save" button that only makes changes to your model once it's triggered.
Alternatively, you could use context.rollback() to discard changes. Also, check out this Project. It's Beta 4 but works just the same and imo is a good example how to use CoreData with SwiftUI. :)

Orientation delegate method is not getting called while rotating the tabs under more section

In my project the tabs which are not under more section are properly responding to orientation but the tabs present under the more section are not responding.
For example if I am having two tabs names tab1 and tab2 under more section and if I am putting break point at the "shouldAutorotateToInterfaceOrientation" method of each tab.After that when if I am selecting tab1 from more section and tries to rotate it but the "shouldAutorotateToInterfaceOrientation" of the tab2 gets called.The delagate method of the tab which I am selecting is not getting called.I am working on XCode Ver 4.3.2.
Can someone please help me in solving this problem..
Thanks in advance,
Prajnaranjan Das
Please write followings code of all the root view controller of tab bar controller.
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return yes;
}
i face the same prblm as you facing now...
i was Return YES (shouldAutorotateToInterfaceOrientation Function) to all the view Controller classes inside tababarcontroller and my problem solved..
try to do this...might be you also get success
I used this method for orientation. Its working properly.
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
}
There are several other methods which may help you in orientation such as:
• willRotateToInterfaceOrientation
• didRotateFromInterfaceOrientation
• willAnimateFirstHalfOfRotationToInterfaceOrientation
• willAnimateSecondHalfOfRotationFromInterfaceOrientation

Appcelerator. Buttons in rows are unclickable

Titanium SDK version: 1.6.2 (tried with 1.7 too)
iPhone SDK version: 4.2
I am developing an iPhone app and I am fetching data from my API and presenting it in a table. In this table I got a button on each row that should allow the user to add that person to his or her contacts. The only problem with the code (I think) is that only the last button responds when being clicked. Nothing happens when I click the other buttons.
This is my code: http://pastie.org/1932098
What is wrong?
You are adding the button.addEventListener outside of the for statement, and since you are overwriting the button var with each iteration, the eventListener only attaches to the last button created.
This probably isn't the best way to work this, but to fix your problem, move the button.addEventListener inside the for statement, and then check for a unique identifier in the object that gets sent to the event. Example:
for (x=0;x<5;x++) {
var button = Titanium.UI.createButton({
height:40,
width:100,
top:50*x,
id:x
});
var label = Titanium.UI.createLabel({
text:'LABEL '+x
});
button.add(label);
win1.add(button);
button.addEventListener('click', function(e){
Ti.API.info('Button clicked '+e.source.id);
});
}
The button.id property is just made up, but now you can see which button sends the event. You could also use title, or anything else that is unique.
Other options to look at are creating unique variable names for each button, but that's probably more work. Also, instead of working with putting a button in the table row, use a label or image, then listen for the event generated by the table or row.