I created a button programmatically to be added to the rightBarButtonItem. I had to create a few buttons in the upper right with the UINavigationController, so I put them in a containerView, and then, put that as the right barButtonItem customView in the init method. If my button and containerView are declared like this:
UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:#"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:#selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];
How do I get the popover to present from the filterButton rect? My method looks like this so far, but it is not correct.
- (IBAction)FilterButtonPressed:(id)sender {
// other code
[self.FilterPopover presentPopoverFromRect:button.superview.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
I display popover usually like this:
[self.FilterPopover presentPopoverFromRect:button.bounds inView:button permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
Related
How can i add the activity indicator beside the right bar button item (CreateNew button)?
One of the approaches that you can use is initializing the Bar Button using some custom view.
A bar minimum code which can help you get some hint is
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIView* aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 40)];
[aView setBackgroundColor:[UIColor blackColor]];
[[aView layer] setCornerRadius:8.0f];
[[aView layer] setBorderColor:[UIColor whiteColor].CGColor];
UIActivityIndicatorView* loadView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[loadView startAnimating];
[aView addSubview:loadView];
[loadView setFrame:CGRectMake(5, 5, 30, 30)];
[loadView release];
UIButton* aButton = [[UIButton alloc] initWithFrame:CGRectMake(30, 2, 80, 35)];
[aButton setImage:[UIImage imageNamed:#"btnLogin.png"] forState:UIControlStateNormal];
[aView addSubview:aButton];
[aButton release];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:aView];
[self.navigationItem setRightBarButtonItem:barButton];
[aView release];
[barButton release];
}
This is If you do it programmatically , else you can also make use of nib. Creating bar button this way will look something like this -
You can look for more option making using of [[UIBarButtonItem alloc] initWithCustomView:aView]; method.
Hope it helps!!
For this try to customize UINavigationController Class.
Add Activity Indicator on navigationBar and control it from your ViewController.
You can add the activity indicator using the following code:
//Create an instance of activity indicator view
UIActivityIndicatorView * activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
//set the initial property
[activityIndicator stopAnimating];
[activityIndicator hidesWhenStopped];
//Create an instance of Bar button item with custome view which is of activity indicator
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
//Set the bar button the navigation bar
[self navigationItem].rightBarButtonItem = barButton;
//Memory clean up
[activityIndicator release];
[barButton release];
Please refer this link for detailed code.
- (void)viewDidLoad{
UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[self.view addSubview:baseView];
// Displays UIImageView
UIImageView *myImage = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"ka1_046.png"]];
myImage.frame = CGRectMake(0, 0, 320, 460);
[baseView addSubview:myImage];
// create the UIToolbar at the bottom of the view controller
toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 425, 320, 40)];
toolbar.barStyle = UIBarStyleBlackOpaque;
[baseView addSubview:toolbar];
How can i make Main VC's UIToolbar which has no navigation controller and no tabbarcontroller global for all VC's
There are several ways,
First: you could instead of presenting the new viewcontrollers, you could just add them to the self.view and minimize their size to fit the view controller minus the tabbar
Second: you could share the instance of the tab bar in some global class, such as app delegate, just create the tab bar in the app delegate and add a property around it, so that other VC can access it, and then at each viewDidLoad of a new VC you would add it
I added a UISearchBar and UISearchDisplayController with a UINavigationController. Because we needed a few buttons in the navigationBar, I created a custom view that contains a few buttons, and put that as the rightBarButtonItem. I notice when I click on the search bar, the keyboard pops up from the bottom, and also moves the UINavigationController's navigationBar off the screen. So now I cannot see what I enter in my UISearchBar. Is there a way to get around this? I've seen other apps that it looks like they use a UINavigationBar + multiple buttons on the LHS or RHS of the navigationBar, so I'm assuming this is possible. Thanks.
UIButton *homeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIImage *house = [UIImage imageNamed:#"icon_house.png"];
[homeButton setImage:house forState:UIControlStateNormal];
[homeButton addTarget:self action:#selector(homePressed:) forControlEvents:UIControlEventTouchUpInside];
UIButton *filterButton = [[UIButton alloc] initWithFrame:CGRectMake(49, 0, 44, 44)];
[filterButton setTitle:#"Filter" forState:UIControlStateNormal];
[filterButton addTarget:self action:#selector(FilterButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
self.SearchEntry = [[[UISearchBar alloc] initWithFrame:CGRectMake(98, 0, 150, 44)] autorelease];
self.SearchEntry.delegate = self;
UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:_searchEntry contentsController:self];
searchDisplayCtlr.searchResultsDataSource = self;
searchDisplayCtlr.searchResultsDelegate = self;
searchDisplayCtlr.delegate = self;
UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 248, 44)];
[containerView addSubview:homeButton];
[containerView addSubview:filterButton];
[containerView addSubview:_searchEntry];
Try to adjust the contentSize of the UIScrollView. Also please take care of the Hierarchy of the controls you have taken. Dont keep UINavigationBar and UISearchView in ScrollView, then it will not move and remains fixed in their position
I have UIView controller class where i have programmatically created a UINAvigationController
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Hmm";
navigationController = [[UINavigationController alloc] init];
//without this instruction, the tableView appears blocked
navigationController.view.frame = CGRectMake(0, 0, 768, 1004); // <-- nav controller should fill the screen
navigationController.navigationBar.barStyle = UIBarStyleDefault;
navigationController.title = #"Hello";
[navigationController.navigationBar setHidden:NO];
[self.view addSubview:navigationController.view];
CGRect frame = CGRectMake(100, 70, 200, 50);
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = frame;
[button setTitle:#"Bejoy" forState:UIControlStateNormal];
[button addTarget:self action:#selector(myButtonClick:) forControlEvents:(UIControlEvents)UIControlEventTouchDown];
[self.view addSubview:button];
}
Now in the button click event
- (void)myButtonClick:(id)sender {
SAPRetailExCustomerSalesOrderDetailViewTVC *customerSalesOrderDetailViewTVC = [[SAPRetailExCustomerSalesOrderDetailViewTVC alloc] initWithNibName:#"SAPRetailExCustomerSalesOrderDetailViewTVC" bundle:nil];
[navigationController pushViewController:customerSalesOrderDetailViewTVC animated:YES];
[customerSalesOrderDetailViewTVC release];
}
Here in the output the view is navigating but the button remains in my view!!!
Also i have to click twice to get the back button in my NavigationController.
Is it because i don't have a title for my navigation bar. How will i set the title here?.
Can someone help me??
Your UIViewcontroller should be the child of the navigation controller and not the other way round. Your UIViewController is not responsible for its own navigation controller.
Use UINavigationController's -initWithRootViewController: where you create your UIViewController object and add the navigation controller's view to the window.
What you are doing is wrong: You add the navigation controller's view to the view controller's one!
I am working on navigation based apps...firstly when I press alert button..its shows label,button,image and below tabbar items...how can we add tab bar items?
The most multipurpose way is to add transparent UIView and then add anything to it:
UIView *buttonsHandlerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];
buttonsHandlerView.backgroundColor = [UIColor clearColor];
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithCustomView:buttonsHandlerView];
[self.navigationItem setRightBarButtonItem:backButtonItem animated:YES];
[backButtonItem release];
//[buttonsHandlerView addSubview:__anything__];
[buttonsHandlerView release];
Or init UIBarButtonItem with title/type and use it as button