Get data to other ViewController with custom UIActivity - ios

I try to add custom icon to UIActivity, and i did it, but i can't set UIACtivity. I want hat when i click the icon open other ViewController and take text and image from UIActivity.
I have this code
- (UIViewController *)activityViewController
{
ViewController *viewController = [[[ViewController alloc] init] autorelease];
viewController.activity = self;
viewController.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
return viewController;
}
but this don't work
- (void)performActivity
{
ViewController *viewController = [[[ViewController alloc] init] autorelease];
[viewController.textField1 setText:self.message];
[viewController.imageView setImage:self.image];
[self activityDidFinish:YES];
}

Related

UISplitViewController - detailView is not showing

In AppDelegate we create an DetailView, then a loginView is presented (UIModalPresentationFullScreen) on top of it. After logged in, loginView is dismissed.
DetailView is having a tableView and when you select a cell/row and 2nd detailView is pushed.
What I did so far:
In AppDelegate I ask for UI_USER_INTERFACE_IDIOM() and when idiom is iPad i create a splitView:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
FirstDetailViewController* fdvc = [[FirstDetailViewController alloc] initWithNibName:#"FirstDetailViewController" bundle:nil];
SecondDetailViewController* sdvc = [[SecondDetailViewController alloc] initWithNibName:#"SecondDetailViewController" bundle:nil];
UINavigationController* fdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:fdvc];
UINavigationController* sdvcNavigationController = [[UINavigationController alloc] initWithRootViewController:sdvc];
splitViewController = [[UISplitViewController alloc] init];
splitViewController.viewControllers = [NSArray arrayWithObjects:fdvcNavigationController, sdvcNavigationController, nil];
After login my LoginView is dismissed and my UISplitViewController is shown, with the 1st DetailView on the left side (master). So everything went fine here.
Now I go to the FirstDetailViewController.m and search for the didSelectRowAtIndexPath because there I find the pushView to SecondDetailViewController in the "iPhone version".
And here is where i am stuck. I have tried several SplitView tutorials and read problems of others regarding splitview.
But I think my problem is some kind of "basic" because I am new to programming / iOS in general and don't know all my tools.
Any help would be appreciated.
When writing apps with a table view and some other sort of "display" view for items in the table, I do this so it works on both devices:
// In App Delegate...
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create views
MyTableViewController* myTable = [[MyTableViewController alloc] init];
MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
UINavigationController* tableNav = [[UINavigationController alloc] initWithRootViewController:myTable];
UINavigationController* detailNav = [[UINavigationController alloc] initWithRootViewController:myDetail];
// Check device type
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Use a split view
UISplitViewController* splitView = [[UISplitViewController alloc] init];
split.viewControllers = #[tableNav, detailNav];
self.window.rootViewController = split;
} else {
// Use a single view for iPhone
self.window.rootViewController = tableNav;
}
}
.
// In table view
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Check device type
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
// Tell the already visible detail view to load something
MyData* data = ...; \\ Get your thing to display however you want
[[NSNotificationCenter defaultCenter] postNotificationName:#"DisplayMyData" object:data];
} else {
// No detail controller exists yet, so create it
MyDetailViewController* myDetail = [[MyDetailViewController alloc] init];
[self.navigationController pushViewController:myDetail animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:#"DisplayMyData" object:data];
}
}
.
// In detail view
-(void) viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(displayData:) name:#"DisplayMyData" object:nil];
}
-(void) displayData:(NSNotification*)notify {
MyData* data = (MyData*) notify.object;
... // Display however...
}

iOS selected tab

I'm trying to determine which tab has been selected by the user. I melded this together from a couple of tutorials on iOS tab bars. In my appDelegate I have this code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-3 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
Is viewControllerArray the delegate for my tabController?
When I place this code on the page nothing happens:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
if (tabBarController.selectedIndex == 0) {
NSLog(#"ok");
}
}
In this case, your app delegate should be the delegate for the tabBarController.
You can simply add self.tabController.delegate = self and make sure that your AppDelegate conforms to the UITabBarControllerDelegate protocol.
I also suggest placing a log outside the if in your delegate method, to confirm that it is actually called.

Loading data in one tab, viewing it another but the table won't reload

I have a tab controller with 4 tabs in it. In the 2nd tab I am entering data and saving that data to a plist. In the 4th tab I am reading the plist back, making an array of one of the dictionary items (company names) and displaying them in a table. I am doing this in the viewDidLoad method.
This works fine for existing data. However, when I add data in the 2nd tab and then go to the 4th tab I can't figure out how to get the table to reload the data...I've tried [table reloadData] in the viewDidAppear method, no luck. Also tried to have a button to reload the data but nothing.
Could someone point me in the right direction on this?
Here's some code:
AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
//We need to implement the view controllers within the tab controller and make the tab controller the root controller of our app - note we are only using view 1-4 at first.
FirstViewController *fistView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
ThirdViewController *thirdView = [[ThirdViewController alloc] initWithNibName:#"ThirdViewController" bundle:nil];
FourthViewController *fourthView = [[FourthViewController alloc] initWithNibName:#"FourthViewController" bundle:nil];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:fistView, secondView, thirdView, fourthView, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
self.window.rootViewController = self.tabController;
//end custom code
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
in my FourthViewController.h:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//add our own image to the tab bar
self.title = #"Results";
self.tabBarItem.image = [UIImage imageNamed:#"btnResults.png"];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
newFileManager = [FileManager new];
NSMutableDictionary* surveyResults = [newFileManager readPlist];
NSMutableArray* tempArray = [[NSMutableArray alloc] init];
for(NSString* thisCompanyName in surveyResults) {
[tempArray addObject:thisCompanyName];
}
companyNames = [[NSArray alloc] initWithArray:tempArray];
NSArray* sortedCompanyNames = [companyNames sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
self.companyNamesTable = sortedCompanyNames;
}
Need to post more code to be sure but I would say you are not initializing the 4th tab everytime. Meaning you code is something like this.
init{
[tab4 init]
}
callview{
[pushView tab4]
}
where as if you did
init{
}
callview{
[tab4 init]
[pushView tab4]
}
(meaning dont init the 4tab till your going to use it)
it should query the plist fresh, without any prior query results in the way

xCode 4.2 UITableView drilldown

I'm a newbie to the xCode world and I had a few questions regarding my application setup.
My application a list of Authors, click on author and get author detail plus book titles, and then click on the book title and get book information, but I'm unable to figure out the show detail part.
I have established a tab view controller that displays UIViewControllers in the window.
//create view controllers
UIViewController *vc1 = [[HomeViewController alloc] init];
UIViewController *vc2 = [[AuthorViewController alloc] init];
UIViewController *vc3 = [[BooksViewController alloc] init];
UIViewController *vc4 = [[GenreViewController alloc] init];
UIViewController *vc5 = [[UserViewController alloc] init];
//create instance of tab bar
self.tabBar = [[UITabBarController alloc] init];
//add views to tab bar
self.tabBar.viewControllers = [NSArray arrayWithObjects:vc1,vc2,vc3, vc4, vc5, nil];
self.window.rootViewController = self.tabBar;
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
[_window addSubview:_tabBar.view];
[self.window makeKeyAndVisible];
return YES;
This works perfectly. My first view "AuthorViewContoller" is a table and I can display data, however I can NOT get the detailController to show.
My AuthorViewController viewDidLoad method
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.author= [[NSArray alloc] initWithObjects:#"One", #"two", nil];
self.detailController = [[AuthorDetailController alloc] init];
and my methoddidSelectRowAtIndexPath:
if(indexPath.row == 0)
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
AuthorDetailController *dc = [[AuthorDetailController alloc] initWithNibName:#"AuthorDetailController" bundle:nil];
dc.title = [author objectAtIndex:indexPath.row];
[self.navigationController pushViewController:dc animated:YES];
}else{
[self.navigationController pushViewController:detailController animated:YES];
}
I'm declaring detailController in my AuthorViewController.h file.
#property (nonatomic, retain) IBOutlet AuthorDetailController *detailController;
You have to actually create a UINavigationController, and have it be part of your controller hierarchy, before you can use pushViewController:animated:. You should really try setting this up in a NIB, instead of code, but in your code you can try this in place of your current vc2 initialization:
UIViewController *vc2 = [[UINavigationController alloc] initWithRootViewController:[[AuthorViewController alloc] init]];

Orientation Problem while using insertSubview

I get an orientation problem while using the following to code to display a view on top of a split view.
[window addSubview:aSplitViewController.view];
[window insertSubview:aViewController.view aboveSubview:aSplitViewController.view];
the plain view has a couple of buttons and labels.
So the problem I am facing is that the first view opens in landscape mode but the labels and buttons on the view are in portrait mode.
UPDATE: Here is some code so if anyone wants to see more details...
In my App Delegate
- (void) makeSplitViewController {
NSMutableArray *controllers = [NSMutableArray arrayWithArray:tabBarController.viewControllers];
// First tabbbar item
// detail view
detailViewController = [[DetailViewController alloc] initWithNibName:#"DetailView" bundle:nil];
UINavigationController *navDetailView = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
navDetailView.hidesBottomBarWhenPushed = YES;
// root view
rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];
rootViewController.detailViewController = detailViewController;
rootViewController.navigationItem.title = #"List";
UINavigationController *navRootView = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];
navRootView.hidesBottomBarWhenPushed = YES;
navRootView.navigationBar.barStyle = UIBarStyleBlackTranslucent;
splitViewController = [[UISplitViewController alloc] init];
splitViewController.tabBarItem.title = #"Face Sheet";
splitViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
splitViewController.navigationItem.title = #"Face Sheet";
splitViewController.viewControllers = [NSArray arrayWithObjects:navRootView, navDetailView, nil];
splitViewController.delegate = detailViewController;
splitViewController.hidesBottomBarWhenPushed = YES;
[controllers addObject:splitViewController];
// Second tabbbar item
scoreViewController = [[ScoreCardViewController alloc] initWithNibName:#"TableViewController" bundle:nil];
scoreViewController.tabBarItem.title = #"Score Card";
scoreViewController.tabBarItem.image = [UIImage imageNamed:#"gear1.png"];
scoreViewController.navigationItem.title = #"Score Card";
[controllers addObject:scoreViewController];
tabBarController.viewControllers = controllers;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Create tabbar
tabBarController = [[UITabBarController alloc] init];
//tabBarController.delegate = self;
// Set window
[window addSubview:splashController.view];
[window insertSubview:tabBarController.view belowSubview:splashController.view];
[self.window makeKeyAndVisible];
application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;
return YES;
}
and here is the code in my SplashScreenView
- (IBAction) proceedButtonClick:(id)sender
{
// Initialize loginpopview
PhysicianLoginViewController *loginViewController = [[PhysicianLoginViewController alloc] init];
popOverController = [[UIPopoverController alloc] initWithContentViewController:loginViewController];
popOverController.popoverContentSize = CGSizeMake(350, 200);
popOverController.delegate = self;
// Set a notification to dismiss it later
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(loginViewControllerDone:) name:#"loginViewControllerDone" object:popOverController.contentViewController];
// Present popover
if ([popOverController isPopoverVisible])
{
[popOverController dismissPopoverAnimated:YES];
}
else
{
[popOverController presentPopoverFromRect:CGRectMake(485, 600, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
}
}
// Dismiss popview controller and setup the tabbar
- (void)loginViewControllerDone:(NSNotification *)notification{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Button in content view controller was tapped, dismiss popover...
[self.popOverController dismissPopoverAnimated:YES];
// remove subview
[self.view removeFromSuperview];
// set tabbar
i3EAppDelegate *appDelegate = (i3EAppDelegate *) [[UIApplication sharedApplication]delegate];
[appDelegate makeSplitViewController];
}
It would be great if someone could point out where I am going wrong. I have been stuck with this problem for quite a few days and I have tried everything that comes to my mind...
UIWindow has a subview that it uses for rotations and puts other views inside of that. You need to insert yourself into the root view (or something lower), not the window. Look at -[UIWindow rootViewController].
UIView *rootView = [[[self window] rootViewController] view];
[rootView addSubview:view];
This will work as long as you're using something with a root view controller. This will work as long as rootViewController isn't nil. If you're doing a raw "View Based" application, then it's usually best to pick another view and add your view as its sibling rather than digging through the undocumented hierarchy:
UIView *sibling = ... (some other view)
[[sibling superview] addSubview:view];

Resources