UITableView - Push a View by clicking on a cell - objective-c

I have created an UITableView with some cells (loaded from an array), when I click on a cell the following code pushes the name with the clicked cell. Is there some easier way to do that? Maybe from within a while loop?
if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Schulsekretariat"]){
Schulsekretariat *schulsekretariat = [[Schulsekretariat alloc] initWithNibName:#"Schulsekretariat" bundle:nil];
[self.navigationController pushViewController:schulsekretariat animated:YES];
[schulsekretariat release];
}
else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Zivilstandesamt"]){
Zivilstandesamt *zivilstandesamt = [[Zivilstandesamt alloc] initWithNibName:#"Zivilstandesamt" bundle:nil];
[self.navigationController pushViewController:zivilstandesamt animated:YES];
[zivilstandesamt release];
}
else if ([[arrayWeitere objectAtIndex:indexPath.row] isEqual:#"Feuerwehr"]){
Feuerwehr *feuerwehr = [[Feuerwehr alloc] initWithNibName:#"Feuerwehr" bundle:nil];
[self.navigationController pushViewController:feuerwehr animated:YES];
[feuerwehr release];
}

NSString *name = [arrayWeitere objectAtIndex:indexPath.row];
Class *myClass = [Class classNamed:name];
myClass *vc = [[myClass alloc] initWithNibName:name bundle:nil];
if (vc != nil) {
[self.navigationController pushViewController:vc animated:YES];
}
[vc release];

Related

Modal View Controller Size

I am trying to display a modal view controller, but keep the navigation bar displaying on the iPad. I've tried the different presentation styles but none work. Is it possible to size it, or display it within right on top of a certain view, instead above the whole view controller?
EDIT: Code added:
- (void)buttonPressed:(id)sender
{
RKWebViewController *webViewController = [[RKWebViewController alloc] initWithNibName:nil bundle:nil];
webViewController.request = [NSURLRequest requestWithURL:_link];
webViewController.webView.delegate = self;
webViewController.shouldDisplayDoneButton = YES;
webViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:webViewController animated:YES];
}
Use -
- (void)buttonPressed:(id)sender
{
RKWebViewController *webViewController = [[RKWebViewController alloc] initWithNibName:nil bundle:nil];
webViewController.request = [NSURLRequest requestWithURL:_link];
webViewController.webView.delegate = self;
webViewController.shouldDisplayDoneButton = YES;
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[webViewController release];
navController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentModalViewController:navController animated:YES];
[navController release];
}

How to show/hide UIPopoverController using a single button with a single action method

The following method is associated with a nav bar button. When the button is pressed, it shows a UIPopoverController
- (IBAction) showTablePopUp:(id) sender {
if (self.tablesPopoverController == nil) {
TablesPopOverViewController *tables = [[TablesPopOverViewController alloc]initWithNibName:#"TablesPopOverViewController" bundle:[NSBundle mainBundle]];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables];
popover.delegate = self;
popover.popoverContentSize=CGSizeMake(280.0, 327.0);
[tables release];
self.tablesPopoverController = popover;
[popover release];
}
[self.tablesPopoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
What I want to do is hiding the popover when the button is pressed the second time:
Click - show popover
Click - hide popover
How can I do it?
This should do what you want:
- (IBAction) showTablePopUp:(id) sender {
if (self.tablesPopoverController == nil) {
TablesPopOverViewController *tables = [[TablesPopOverViewController alloc]initWithNibName:#"TablesPopOverViewController" bundle:[NSBundle mainBundle]];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:tables];
popover.delegate = self;
popover.popoverContentSize=CGSizeMake(280.0, 327.0);
[tables release];
self.tablesPopoverController = popover;
[self.tablesPopoverController presentPopoverFromBarButtonItem:sender
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self.tablesPopoverController dismissPopoverAnimated: YES];
self.tablesPopeverController = nil;
}
}

set array .viewControllers from SplitViewController

I'm trying to use a splitview inside a TabBar. By now I have a SplitView in my first TabBarItem. My problem comes when I try to access to a different DetailView or right view in the SplitViewController I have.
I'm trying to do it inside the didSelectRowAtIndexPath: of my Root (or Master) viewcontroller from the SplitView.
Here's the code, where I try to acces to my TabBarController from an AppDelegate object, and change the viewControllers array of my SplitView only changing the second view controller. I always get this crash error, saying that 2nd instance send is unrecognized: -[SecondViewController viewControllers]: unrecognized selector sent to instance 0x6852460
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//object AppDelegate
AppDelegate *myDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//Objecte in Index 0 is my SplitVC
NSArray *barControllers = myDelegate.tabBarController.viewControllers;
if (indexPath.row == 0)
{
SplitVC *temporalSplit = [barControllers objectAtIndex:indexPath.row];
NSArray *mArray = temporalSplit.viewControllers;
FirstViewController *detail = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navigationDetail = [[UINavigationController alloc]initWithRootViewController:detail];
temporalSplit.delegate = detail;
temporalSplit.viewControllers = [[NSArray alloc] initWithObjects:[mArray objectAtIndex:0], navigationDetail, nil];
myDelegate.tabBarController.viewControllers = [NSArray arrayWithObjects:temporalSplit.viewControllers, [barControllers objectAtIndex:1], nil];
}
else if (indexPath.row == 1)
{
SplitVC *temporalSplit = [barControllers objectAtIndex:indexPath.row];
NSArray *mArray = temporalSplit.viewControllers;
Detail2VC *detail = [[Detail2VC alloc]initWithNibName:#"Detail2VC" bundle:nil];
UINavigationController *navigationDetail = [[UINavigationController alloc]initWithRootViewController:detail];
temporalSplit.delegate = detail;
temporalSplit.viewControllers = [[NSArray alloc] initWithObjects:[mArray objectAtIndex:0], navigationDetail, nil];
myDelegate.tabBarController.viewControllers = [NSArray arrayWithObjects:[barControllers objectAtIndex:0], temporalSplit, nil];
}
[myDelegate release];
}
And my AppDelegate code (that works without problems):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
// Override point for customization after application launch.
NSMutableArray *controllersBar = [[NSMutableArray alloc]init];
UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil] autorelease];
for (int i = 0; i<2; i++)
{
if(i == 0)
{
_firstViewController = [[[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil] autorelease];
_masterApp = [[MasterVC alloc]initWithNibName:#"MasterVC" bundle:nil];
_masterApp.firstViewController = _firstViewController;
_firstViewController.mastervc = _masterApp;
UINavigationController *navigationMaster = [[UINavigationController alloc]initWithRootViewController:_masterApp];
UINavigationController *navigationDetail = [[UINavigationController alloc]initWithRootViewController:_firstViewController];
_splitVC = [[SplitVC alloc] initWithNibName:nil bundle:nil];
//_splitVC.tabBarItem = controller.tabBarItem;
_splitVC.viewControllers = [NSArray arrayWithObjects:navigationMaster, navigationDetail, nil];
_splitVC.delegate = _firstViewController;
[controllersBar addObject:_splitVC];
}
else if (i == 1)
{
[controllersBar addObject:viewController2];
}
}
//self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
_tabBarController.viewControllers = controllersBar;
_tabBarController.selectedIndex = 0;
_tabBarController.delegate = self;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
What am I doing wrong? Any help or suggestion is welcome.
Thanks to all in advance.
Split view controller MUST be root level controllers:
UISplitviewcontroller not as a rootview controller
If not, you can apparently get all sorts of strange things happening.

Dismiss an add contact view controller from a UIPopover

Hi In my app I have a button so when you click it a UIPopover comes up with an add contact view in it. It all workers except when you press save. It doesn't Dismiss.
-(IBAction) addcontact
{
ABNewPersonViewController *contacts = [[ABNewPersonViewController alloc] init];
// imagePicker.delegate = self;
// UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:contacts];
UINavigationController *addContactNavController = [[UINavigationController alloc] initWithRootViewController:contacts];
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
popover.popoverContentSize = CGSizeMake(320, 1000);
[popover presentPopoverFromRect:CGRectMake(935, 270, 175, 300)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionRight
animated:YES];
[popover retain];
[addContactNavController release];
[contacts release];
}
Implement the ABNewPersonViewControllerDelegate protocol and assign the delegate in your method above –
contacts.newPersonViewDelegate = self;
You can then dismiss the popover in the delegate function –
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView
didCompleteWithNewPerson:(ABRecordRef)person {
[popOver dismissPopoverAnimated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[popOver release];
}
well,
[self dismissModalViewControllerAnimated:YES];
respecively
[popover dismissPopoverAnimated:YES];
should do it?
Edit: to be more concrete:
....
popover = [[UIPopoverController alloc] initWithContentViewController:addContactNavController];
addContactNavController.delegate = self;
now on saving, do something like:
-(IBAction) saveStuff {
... saving...
[delegate closePopup];
}
and in your File with -(IBAction) addcontact you do:
-(void) closePopup {
[self dismissModalViewCotroller...];
}
makes sense?
and yes, you should add a delegate-propery to your controller if not done yet

How do I change modalTransitionStyle?

I am currently using this code to bring up an info window
-(IBAction)showInfo:(id)sender {
InfoView *info = [[InfoView alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
[self presentModalViewController:info animated:YES];
[info release];
}
It currently uses the default transition style, UIModalTransitionStyleCoverVertical, and I would like to make it use a different transition style, UIModalTransitionStyleFlipHorizontal for example, how do I do this?
from apple documentation
http://developer.apple.com/iphone/library/samplecode/AddMusic/Listings/Classes_MainViewController_m.html#//apple_ref/doc/uid/DTS40008845-Classes_MainViewController_m-DontLinkElementID_6
MusicTableViewController *controller = [[MusicTableViewController alloc] initWithNibName: #"MusicTableView" bundle: nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController: controller animated: YES];
[controller release];
- (IBAction)next {
page2 *page2_xib = [[page2 alloc] init];
page2_xib.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
//page2_xib.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//page2_xib.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:page2_xib animated:YES];
}