I have two view controllers. The first is the login page and the second is the user cabinet. When I sign in and go to second view I can see back button "FirstController" at the Navigation Bar. But I don't need of this button and I want to have rect button as a "Sign Out".
Question: how can I set rect button "Sign Out" as a back button?
Hide UINavigationbar's Hide button while requesting to load from login page & while loading "FirstController", initialize your UIBarButtonItem with custom view - UIButton (Sign Out button) and also set selector to respond as click on "Sign Out".
Sample Code:
To Hide back button:
self.navigationItem.hidesBackButton = TRUE;
To add "Sign Out" button:
-(void)setMySignOut
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:#"btn_logout.png"] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:#"btn_logout_h.png"] forState:UIControlStateHighlighted];
button.frame = CGRectMake(0, 0, 70, 30);
[button addTarget:self action:#selector(btnLogoutClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc] initWithCustomView:button];
}
-(void)btnLogoutClicked:(UIButton *)sender
{
// your logic goes here...
}
Related
I am trying to use GWT PopupPanel (or DialogBox) with glass and autohide enabled to create a context actions menu on mobile devices, but I have an issue when the user whats to close the actions menu popup (by tapping on the glass of the popup, outside the content to trigger autohide): the underlying widgets ("beneath" the glass) also receive the tap event when the popup is closed. For example, if there is a button at that position that opens a new view/window, the button is clicked and executes his click handler.
My code:
public void onModuleLoad() {
Button button = new Button("Test");
button.addClickHandler(cl -> {
Label lb = new Label("This is the content");
lb.getElement().getStyle().setBackgroundColor("#fff");
lb.setSize("200px", "80px");
DialogBox pop = new DialogBox();
pop.setAutoHideEnabled(true);
pop.setGlassEnabled(true);
pop.setWidget(lb);
pop.center();
});
Button buttonBehindGlass = new Button("Test over");
buttonBehindGlass.addClickHandler(cl -> {
Window.alert("Action 2");
});
RootPanel.get().add(button);
RootPanel.get().add(buttonBehindGlass);
}
In this example, if you open the popup, then click/tap outside the content, on the glass, over the "buttonBehindGlass" widget, you will notice that the popup closes and "buttonBehindGlass" is clicked, at the same time.
Is there any way to avoid this?
I tested on Android and Chrome dev tools enabled with responsive/touch mode. This issue does not appear on desktop, everything is fine there.
Create your own DialogBox, based on the GWT one
public class DialogBoxExtended extends DialogBox {
#Override
protected void onPreviewNativeEvent(NativePreviewEvent event) {
super.onPreviewNativeEvent(event);
// check if the event does not target the popup
Event nativeEvent = Event.as(event.getNativeEvent());
if (!eventTargetsPopup(nativeEvent)) {
// on click, touch end, etc. close the dialog box
switch (event.getTypeInt()) {
case Event.ONMOUSEDOWN:
case Event.ONCLICK:
case Event.ONTOUCHEND:
hide();
break;
}
}
}
/**
* Does the event target this popup?
*
* #param event the native event
* #return true if the event targets the popup
*/
private boolean eventTargetsPopup(NativeEvent event) {
EventTarget target = event.getEventTarget();
if (Element.is(target)) {
return getElement().isOrHasChild(Element.as(target));
}
return false;
}
}
disable auto hide and use your created DialogBox
public void onModuleLoad() {
Button button = new Button("Test");
button.addClickHandler(cl -> {
Label lb = new Label("This is the content");
lb.getElement().getStyle().setBackgroundColor("#fff");
lb.setSize("200px", "80px");
DialogBox pop = new DialogBoxExtended();
pop.setAutoHideEnabled(false);
pop.setGlassEnabled(true);
pop.setWidget(lb);
pop.center();
});
Button buttonBehindGlass = new Button("Test over");
buttonBehindGlass.addClickHandler(cl -> {
Window.alert("Action 2");
});
RootPanel.get().add(button);
RootPanel.get().add(buttonBehindGlass);
}
It now works as expected.
With auto hide enabled the event is processed but left to be consumed by other handlers - that's why the event gets to the underlying button. On desktop it was not a problem because Event.ONMOUSEUP was being considered, but on mobile/touch mode the Event.ONTOUCHEND is being triggered instead.
When you make a SpanButton lead for a Container, it doesn't receive the events. I've tried debugging but haven't managed to understand why it doesn't work. It seems to be a CN1 error, but I may have misunderstood something.
Here's a test case to reproduce the issue:
Form hi = new Form("Welcome", BoxLayout.y());
//test case shows that when you make a normal Button lead for a Container,
//it works as expected.
//Doing the same with a SpanButton doesn't work.
//When you click button it correctly hides the Label.
//Clicking spanButton doesn't hide the label.
//
//Test also shows a second issue: when adding a Command to a SpanButton,
//the Command text is shown in parallel with the SpanButton's text
//edit Button works normal
Button button = new Button("Normal Button works");
Label hide2 = new Label("Now you see me, now you don't2");
Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
hide2.setHidden(!hide2.isHidden());
hi.revalidate();
});
button.setCommand(cmd2);
Label editButtonLabel2 = new Label();
FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
cont2.setLeadComponent(button); //for a normal button, the lead works correctly
hi.add(cont2);
hi.add(hide2);
//with SpanButton it doesn't work:
SpanButton spanButton = new SpanButton("SpanButton does not work");
Label hide = new Label("Now you see me, now you don't");
Command cmd = Command.create("CmdText", null, (ev) -> {
hide.setHidden(!hide.isHidden());
hi.revalidate();
});
spanButton.setCommand(cmd);
Label editButtonLabel = new Label();
FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
cont.setLeadComponent(spanButton); //spanButton made lead for cont, so should receive all events for cont, but doesn't
hi.add(cont);
hi.add(hide);
hi.show();
Could this be due to SpanButton being a container itself and also having a Lead component which is a Button?
You could create a normal Button and apply that command to it, then set the container's lead component to this Button. You don't have to add this Button to the container, add your SpanButton and the container will still receive all the events.
Form hi = new Form("Welcome", BoxLayout.y());
/*test case shows that when you make a normal Button lead for a Container,
it works as expected.
Doing the same with a SpanButton doesn't work.
When you click the button, it correctly hides the Label.
Clicking spanButton doesn't hide the label.
Test also shows a second issue: when adding a Command to a SpanButton,
the Command text is shown in parallel with the SpanButton's text*/
//edit Button works normal
Button button = new Button("Normal Button works");
Label hide2 = new Label("Now you see me, now you don't2");
Command cmd2 = Command.create("CmdTxt2", null, (ev) -> {
hide2.setHidden(!hide2.isHidden());
hi.revalidate();
});
button.setCommand(cmd2);
Label editButtonLabel2 = new Label();
FontImage.setMaterialIcon(editButtonLabel2, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont2 = BorderLayout.centerEastWest(button, editButtonLabel2, null);
cont2.setLeadComponent(button); //for a normal button, the lead works correctly
hi.add(cont2);
hi.add(hide2);
//with SpanButton it doesn't work:
SpanButton spanButton = new SpanButton("SpanButton does not work");
Label hide = new Label("Now you see me, now you don't");
Command cmd = Command.create("CmdText", null, (ev) -> {
hide.setHidden(!hide.isHidden());
hi.revalidate();
});
Button btnHidden = new Button(cmd);
Label editButtonLabel = new Label();
FontImage.setMaterialIcon(editButtonLabel, FontImage.MATERIAL_CHEVRON_RIGHT); // [>]
Container cont = BorderLayout.centerEastWest(spanButton, editButtonLabel, null);
cont.setLeadComponent(btnHidden); //spanButton made lead for cont, so should receive all events for cont, but doesn't
hi.add(cont);
hi.add(hide);
hi.show();
I want to disabled context menu (click right mouse) depending of resolution.
This is my js code:
angularRoutingApp.controller('mainController', function($scope,$window) {
var w = angular.element($window);
$(w).resize(function(){
if (window.innerWidth<1024) {
// here i disabled the click right mouse
}
});
});
Any idea? thanks,
I have a view that pops up a UIAlertView if the name field for an item entry isn't populated when you attempt to save. I wanted to display my own custom alert view instead. I load it with a xib:
- (void)enterNameAlert {
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"AddNameAlertView" owner:self options:nil];
enterNameAlertView = [subviewArray objectAtIndex:0];
enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
enterNameAlertView.alpha = 0.0;
[self.view addSubview:enterNameAlertView];
[self.view bringSubviewToFront:enterNameAlertView];
//fade view in
[UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {
enterNameAlertView.alpha = 1.0;
} completion:NULL];
[UIView commitAnimations];
}
However, you can still click on all the other elements on the view while the alert is displayed. Ideally, I'd like to make the alertview modal. As a hack, I just set xxxx.enabled = NO to all the other elements while the alertview is up, and switch them back to xxxx.enabled = YES when you press OK on the alert.
There has to be a better way to cancel all touches to self.view but not to self.enterNameAlertView.
If I do self.view.userInteractionEnabled = NO it cancels all touches to self.view as well as self.enterNameAlertView.
Any ideas?
I think the solution for your problem is that you have to introduce one more view in between your custom alert view and orignal view, once the alert comes you need to bring that view on your self.view and hide (or remove) it when your alert is dismissed, i have already done this and it work like charm for me. Hope this helps you too :)
Got it. I used a UIScrollView with interaction enabled. That stops touches from outside the custom alertview from being passed to the main view underneath.
- (void)enterNameAlert {
//pop a UIScrollView behind the alert so that the user can't touch the controls behind it
shadowScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
shadowScrollView.userInteractionEnabled = YES;
shadowScrollView.backgroundColor = [UIColor blackColor];
shadowScrollView.alpha = 0.0;
[self.view addSubview:shadowScrollView];
[self.view bringSubviewToFront:shadowScrollView];
//put the alertview in front of the disabled view to make it act like a modal view
NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:#"AddNameAlertView" owner:self options:nil];
enterNameAlertView = [subviewArray objectAtIndex:0];
enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
enterNameAlertView.alpha = 0.0;
[self.view addSubview:enterNameAlertView];
[self.view bringSubviewToFront:enterNameAlertView];
//animate view in
[UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {
shadowScrollView.alpha = .6;
enterNameAlertView.alpha = 1.0;
} completion:NULL];
[UIView commitAnimations];
}
Using Titanium mobile sdk 1.7.2, I created a tabgroup with 11 tabs. The problem is when I open any of the tabs inside the 'more' tab, if the child window has a right navbar button, some times the 'edit' button of the 'more' tab doesn't go away..
my code is:
app.js:
var tabGroup=Titanium.UI.createTabGroup({top:20});
............
/** list of windows and tabs **/
............
var win9 = Titanium.UI.createWindow({
url:'discover.js',
title:'Discover',
navBarHidden:true,
barColor: navBarColor
});
var tab9 = Titanium.UI.createTab({
icon:'images/icons/Discover.png',
title:'Discover',
window:win9
});
discover.js:
win=Titanium.UI.currentWindow;
var btn=Titanium.UI.createButton({title:'Discover'});
btn.addEventListener('click',function (){
//do some stuff
});
win.rightNavButton=btn;
the problem is, sometimes when I open the 'tab9' which opens 'win9' my button (btn) doesn't appear, the 'edit' button of the 'more' is shown instead.
N.B: the click event listener works just fine, It is the 'edit' title that persists. Any one knows how to solve this?
thank you,
You need to set allowUserCustomization:false in your Tabgroup.
var tabGroup=Titanium.UI.createTabGroup({top:20,allowUserCustomization:false});
try to set
win.rightNavButton = null;
win.rightNavButton = btn;