MKMapView in presentModalView black - iphone

I have 2 uiviewcontroller
- first one is the rootviewcontroller
- second one is a UIViewController with a mapview inside (MyMap.m/MyMap.h)
My problem is that when I try to show my second view as modalview from the first view my mapview is completely black.
this is the viewdidload of my second view, i try to set as initial view and the mapview works:
- (void)viewDidLoad{
[super viewDidLoad];
mapView.delegate =self;
mapView.showsUserLocation = YES;
UIBarButtonItem *zoomButton =
[[UIBarButtonItem alloc]
initWithTitle: #"Zoom"
style:UIBarButtonItemStylePlain
target: self
action:#selector(zoomIn:)];
UIBarButtonItem *typeButton =
[[UIBarButtonItem alloc]
initWithTitle: #"Type"
style:UIBarButtonItemStylePlain
target: self
action:#selector(changeMapType:)];
NSArray *buttons = [[NSArray alloc]
initWithObjects:zoomButton, typeButton, nil];
toolBar.items = buttons;
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = 47.640071;
annotationCoord.longitude = -122.129598;
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = #"Microsoft";
annotationPoint.subtitle = #"Microsoft's headquarters";
[mapView addAnnotation:annotationPoint];
}
and this is my first view action
MyMap *map = [[MyMap alloc]init];
[self presentModalViewController:map animated:YES];
I don't know why my mapview is turning black when i launch it from first view and not when i launch it as initial view any ideas ?

Related

problem with UIPopoverController while navigation

I have UIPopoverController and two ViewController class.
SaveProject and ProjectName is viewController class.
When i am clicking save project. its give me navigation and load another view.
But the UIPopoverController size height is getting increased to the total view size.
Can any one help me out with this..
I am attaching here code:
-(void)createSaveAndCloseView{
saveAndCloseViewController = [[WGSaveAndCloseViewController alloc]init];
[saveAndCloseViewController.view setFrame:CGRectMake(0, 0, 310, 171)];
saveAndCloseViewController.navigationItem.title = #"Save or Discard";
UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStylePlain target:self action:#selector(cancelAction:)];
saveAndCloseViewController.navigationItem.rightBarButtonItem = cancel;
[cancel release];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController:saveAndCloseViewController];
saveAndClosePopupView = [[UIPopoverController alloc] initWithContentViewController:navControl];
saveAndClosePopupView.delegate = self;
saveAndClosePopupView.popoverContentSize = CGSizeMake(312, 160);
saveAndCloseViewController.view.contentMode = UIViewContentModeScaleAspectFill;
[saveAndClosePopupView presentPopoverFromRect:[saveAndClose bounds] inView:saveAndClose permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[navControl release];
}
-(void)saveProjectClick:(id)sender{
if (saveProject.tag == tagSave) {
WGNameProjectViewController *nameProjectViewController = [[WGNameProjectViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:nameProjectViewController animated:YES];
nameProjectViewController.navigationItem.title = #"Name Project";
[nameProjectViewController release];
nameProjectViewController = nil;
}
}
You just need to add something like:
self.preferredContentSize = <view size>
to the viewWillAppear: method in each of your view controllers that are displayed in the popover.

unable to get title bar and navigation button items

I have added a new file to my project in that i am creating the screens programatically and i used following code to create a grouped table view with a title bar & 2 buttons on title bar, but its creating only grouped table but not title bar y it is so, can any one help me thanx in advance
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Add Item";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(cancel_Clicked:)] autorelease];
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:#selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 415)style:UITableViewStyleGrouped];
tableView.dataSource = self;
tableView.delegate = self;
[self.view addSubview:tableView];
}
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithTitle:#"+"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
[journeylist.tabBarItem initWithTitle:#"Journey List" image:[UIImage imageNamed:#"listIcon-H.png"] tag:1];
journeylist.navigationItem.title =#"Journey List";
NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
self.viewControllers = controllers;
Try this.
Your table frame is CGRectMake(0, 0, 320, 415) so top left, you'll need to leave room for the title bar say CGRectMake(0, 40, 320, 415).
I think you have to present it like this.
SomeViewController *controller = [[SomeViewController alloc]
initWithNibName:#"SomeViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:controller];
navController.navigationBar.tintColor = [UIColor grayColor];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[controller release];
Edit
When you are showing that controller with table view you have to frist add it to a navigation controller in order to show the navigation bar.

How to resize UITableView within UINavigationController within UITabBarViewController?

So my app has a UITabBarController. Within that, one of the tabs is a UIViewController containing a UINavigationController. Within that is a UITableViewController.
The problem is that for some reason the size of the TableView is off, and part of the bottom entry of the table is obscured by the TabBar. I've tried everything I can think of to resize the tableview but to no avail. Here are the relevant parts of the code:
AppDelegate
tabBarController = [[UITabBarController alloc] init];
LogbookViewController *firstVC = [[LogbookViewController alloc] init];
PaceCalcViewController *secondVC = [[PaceCalcViewController alloc] init];
SettingsTableViewController *thirdVC = [[SettingsTableViewController alloc] init];
...
// Add them as children of the tab bar controller
tabBarController.viewControllers = [NSArray arrayWithObjects: firstVC, secondVC, thirdVC, nil];
LogbookViewController (subclass of UIViewController)
- (void)viewDidLoad {
[super viewDidLoad];
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];
WorkoutListTableViewController *listController = [[WorkoutListTableViewController alloc] init];
listController.managedObjectContext = self.managedObjectContext;
[navigationController pushViewController:listController animated:NO];
[listController release];
}
The WorkoutListTableViewController (subclass of UITableViewcontroller) currently doesn't have anything in particular in it that I would think would affect it, but here's the ViewDidLoad:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"Workouts";
self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"List" style:UIBarButtonItemStyleBordered target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
NSString *paths = [[NSBundle mainBundle] resourcePath];
NSString *fileName = #"short_bg.png";
NSString *filePath = [paths stringByAppendingPathComponent:fileName];
UIImage *paper = [[UIImage alloc] initWithContentsOfFile:filePath];
UIImageView *paper_bg = [[UIImageView alloc] initWithImage:paper];
self.tableView.backgroundView = paper_bg;
[fileName release];
[paper release];
//self.navigationItem.leftBarButtonItem = self.editButtonItem;
UIBarButtonItem *addButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(add:)];
self.navigationItem.rightBarButtonItem = addButtonItem;
[addButtonItem release];
/*UIBarButtonItem *importButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Import" style:UIBarButtonItemStylePlain target:self action:#selector(importDialogAction:)];
self.navigationItem.leftBarButtonItem = importButtonItem;
[importButtonItem release];*/
}
}
I've tried things like listController.view.frame = CGRectMake(whatever) in the LogbookViewcontroller, or self.tableView.frame - CGRectMake(whatever) in the WorkoutListTableViewController, but nothing has worked. Any ideas? I can post more of the code if that helps.
You should be added the Navigation Controller directly to the UITabBarController, then it should size appropriately:
tabBarController = [[UITabBarController alloc] init];
WorkoutListTableViewController *listController = [[WorkoutListTableViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:listController];
PaceCalcViewController *secondVC = [[PaceCalcViewController alloc] init];
SettingsTableViewController *thirdVC = [[SettingsTableViewController alloc] init];
...
// Add them as children of the tab bar controller
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, secondVC, thirdVC, nil];
You don't need the View Controller in the 1st tab to add a UINavigationController to the view, just go ahead and add the TableViewController as the root of the nav controller and add the nav controller into the 1st tab.

Left Arrow - UINavigationItem

I've searched around and I can't seem to figure it out. I'm sure many people will have links for me and such, which I've most likely already looked at. But if someone could please just show me code to do the following:
I'd like to have a left arrow in my UINavigationBar as a "Back" UINavigationItem. How can I do this? Here is my current code in my UIViewController:
theBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleBordered target:nil action:#selector(backButtonSelected:)];
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Options" style:UIBarButtonItemStyleBordered target:nil action:#selector(optionsButtonSelected:)];
UINavigationItem *item = [[UINavigationItem alloc] initWithTitle:#"Title"];
item.leftBarButtonItem = leftButton;
item.hidesBackButton = YES;
item.rightBarButtonItem = rightButton;
[self.view addSubview:theBar];
I think this may be what you're looking for.
// in .h file
#property (nonatomic, retain) UINavigationBar *navBar;
// in .m file just below #implementation
#synthesize navBar;
// within .m method
navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
navBar.barStyle = UIBarStyleBlack;
UINavigationItem *title = [[UINavigationItem alloc] initWithTitle:#"Nav Bar Title"];
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]
initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:#selector(backButtonSelected:)];
title.leftBarButtonItem = leftButton;
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAction
target:nil
action:#selector(showActionSheet:)];
title.rightBarButtonItem = rightButton;
[navBar pushNavigationItem:title animated:YES];
[self.view addSubview:navBar];
You should use an UINavigationController in order to pop/push UIViewControllers on your screen. The navigation controller will add an UINavigationBar to your UIViewControllers automatically so you will not need to create them as you did.
Here is a sample. I didn't looked for memory leaks.
In the app delegate you'll find this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
MainVC *mainVC = [[MainVC alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainVC];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}
MainVC is a UIViewController that represents the level 1 of the hierarchy. in it i have
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
self.view.backgroundColor = [UIColor redColor];
self.title = #"MainVC";
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"SecondLevel" style:UIBarButtonItemStyleBordered target:self action:#selector(secondLevelSelected:)];
self.navigationItem.rightBarButtonItem = rightButton;
}
- (void) secondLevelSelected:(id)sender
{
SecondVC *secondVC = [[SecondVC alloc] init];
[self.navigationController pushViewController:secondVC animated:YES];
}
SecondVC is another UIViewController that represents the second level of the hierachy. Here you will find the back button that you want.
- (void)loadView
{
self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 240)];
self.view.backgroundColor = [UIColor greenColor];
self.title = #"SecondVC";
self.navigationItem.hidesBackButton = YES;
UIBarButtonItem *leftBtn = [[UIBarButtonItem alloc] initWithTitle:#"FirstLevel" style:UIBarButtonItemStyleBordered target:self action:#selector(leftBtnSelected:)];
self.navigationItem.leftBarButtonItem = leftBtn;
}
- (void) leftBtnSelected:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}

Navigation Items in UITableViewController are not appearing?

I am displaying a UITableViewController inside of a UITabBarController that is being presented modally:
-(IBAction)arButtonClicked:(id)sender{
//this is a uitableviewcontroller
ARViewController* arViewController = [[[ARViewController alloc] initWithNibName:#"ARViewController" bundle:nil]autorelease];
LeaderBoardTableViewController* lbViewController = [[[LeaderBoardTableViewController alloc] initWithNibName:#"LeaderBoardTableViewController" bundle:nil]autorelease];
lbViewController.title = #"Leaderboard";
arTabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
arTabBarController.viewControllers = [NSArray arrayWithObjects:arViewController, lbViewController, nil];
arTabBarController.selectedViewController = arViewController;
[self presentModalViewController:arTabBarController animated:YES];
}
In my viewDidLoad for arViewController method I am setting the navigation items:
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
self.title = #"AR";
leaderBoardButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemOrganize
target:self
action:#selector(leaderBoardButtonClicked:)];
self.navigationItem.rightBarButtonItem = leaderBoardButton;
}
My navigation bar doesn't appear when it is inside of the UITabBarController, but when I push the view itself I am able to see it.
What am I missing?
Heh, I've been stumped by this too. What you need to do is send the rootViewController.
I've never used a tabBar for anything except on the main screen but ur code will probably look like this:
after arTabBarController.selectedViewController = arViewController;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController: arTabBarController] autorelease];
[self presentModalViewController: navController animated:YES];
Like I said I haven't done it with a tabBar but I'm pretty sure it will be something along these lines
I needed to add a UINavigationBar:
ARViewController* arViewController = [[[ARViewController alloc] initWithNibName:#"ARViewController" bundle:nil]autorelease];
UINavigationController *arNavController = [[UINavigationController alloc] initWithRootViewController:arViewController];
LeaderBoardTableViewController* lbViewController = [[[LeaderBoardTableViewController alloc] initWithNibName:#"LeaderBoardTableViewController" bundle:nil]autorelease];
lbViewController.title = #"Leaderboard";
UINavigationController *lbNavController = [[UINavigationController alloc] initWithRootViewController:lbViewController];
arTabBarController = [[UITabBarController alloc] init];//initWithNibName:nil bundle:nil];
arTabBarController.viewControllers = [NSArray arrayWithObjects:arNavController, lbNavController, nil];
arTabBarController.selectedViewController = arNavController;
[self presentModalViewController:arTabBarController animated:YES];
There is a simple solution, put setting in view will appear
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
hope it help some newbies;