I am making an replica of Scrumptous sample app (ios facebook sdk version - 3.10 ) using Storyboard approach
I am able to load user name and profile image correctly.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do nothing for now
switch (indexPath.row) {
case 2:
if (!self.friendPickerController) {
self.friendPickerController = [[FBFriendPickerViewController alloc]
initWithNibName:nil bundle:nil];
// Set the friend picker delegate
self.friendPickerController.delegate = self;
self.friendPickerController.title = #"Select friends";
}
[self.friendPickerController loadData];
[self.navigationController pushViewController:self.friendPickerController
animated:true];
break;
}
}
With below approach we can instantiateViewController but we need a valid identifier
/*
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
[self presentViewController:vc animated:YES completion:NULL];
*/
Related
I would like to push to ParcelPickUpViewController after I clicked a button in LocationDetailsTableViewCell xib. But I've written the code below and it able to run. But the result won't happen at all. Need help on this issue. Thanks.
In LocationDetailsTableViewCell.h
#property (nonatomic, strong) UINavigationController *viewController;
In LocationDetailsTableViewCell.m
- (IBAction)selectBtn:(id)sender {
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
}
I think you have button in UITableViewCell.Now you want to navigate to next view from the button click.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:nil options:nil];
cell = [nibObjects objectAtIndex:0];
}
cell.btnSelct.tag = indexPath.row;
[cell.btnSelct addTarget:self action:#selector(selectBtn:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (IBAction)selectBtn:(id)sender
{
//This is for XIB
ParcelPickUpViewController *vc = [[ParcelPickUpViewController alloc]initWithNibName:#"pickUpVC" bundle:nil];
//If you use storyboard
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: #"parcelpickup"];
[self.viewController pushViewController:vc animated: YES];
}
Try This ...
- (IBAction)selectBtn:(id)sender {
ParcelPickUpViewController *vc = [[HomeScreenVC alloc]initWithNibName:#"pickUpVC" bundle:nil];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
}
option 2
you are created the Navigation controller not allocated the memory of your instance navigation controller, so do like
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
self.viewController = [[UINavigationController alloc] init];
[self.viewController pushViewController:vc animated: YES];
[self.viewController setNavigationBarHidden:YES animated:YES];
if you no need the setNavigationBarHidden then use like
option 3
UIStoryboard *mainStoryBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ParcelPickUpViewController *vc = [mainStoryBoard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self presentViewController:vc animated:YES completion:nil];
(1) Make sure you have set the isInitialViewController(the first controller you want to display when app launch) in storyboard.
(2) If you did not add UINavigationController in storyboard, create it programeticaly and set it as rootViewController w.r.t your InitialViewController in app delegate didFinishLaunchingWithOptions.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *storyboard = storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:Nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"Your_First_View_Controller_Identifier"];
UINavigationController *rootNavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
self.window.rootViewController = rootNavigationController;
return YES;
}
(3) While navigating to your ParcelPickUpViewController just simply add below code:
- (IBAction)selectBtn:(id)sender {
ParcelPickUpViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier: # "pickUpVC"];
[self.navigationController pushViewController:vc animated: YES];
}
I have a table view with some cells on it. When I tap on single-cell my app just gets crashed on the real iOS device but the app works fine on the simulator. Please tell me why the app crashing on a real device, not on the simulator.
Following is code for the app:-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"BusinessCard"];
[self.navigationController pushViewController:vc animated:YES];
}
else if(indexPath.row==1)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"NonBusinessCard"];
[self.navigationController pushViewController:vc animated:YES];
}
else if(indexPath.row==2)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"EventCard"];
[self.navigationController pushViewController:vc animated:YES];
}
}
I'm working in iOS app but I'm trying to present a tableview when I click a button in one of my scenes like it shows in the image bellow:
I tried this way:
- (IBAction)presentScene:(id)sender
{
NSString *storyboardName = #"Main";
NSString *viewControllerID = #"myScene";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
MyViewController *controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
[self presentViewController:_categoViewController animated:YES completion:nil];
}
But doesn't show the navigation to go back to the main table view or I can't even set the title of the tableview. Any of you knows how can present tableview?
try this:
[[self navigationController] pushViewController:YOUR_DESTINATION_VIEW_CONTROLLER animated:YES];
You should present the tableViewController with UINavigationController like so:
MyViewController *controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentViewController:navigationController animated:YES completion:nil];
EDIT:
You should add a UINavigationController in your storyboard like this:
If you do not want to show the navigationBar in your HomeVC then hide it:
// HomeVC.m
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Finally, push the MyViewController:
- (IBAction)presentScene:(id)sender {
NSString *viewControllerID = #"myScene";
UIStoryboard *storyboard = self.storyboard;
MyViewController *controller = (MyViewController *)[storyboard instantiateViewControllerWithIdentifier:viewControllerID];
[self.navigationController pushViewController: controller animated:YES]
}
After experimenting with everything I finally found what I was looking for:
self.tabBarController.selectedIndex = 1;
iPadApp:i have a two classes TimeTableViewController and MLCViewController created a protocol in MLCViewController and that protocol i want to call in the TimeTableViewController . But the delegate(protocol) method is not calling in the TimeTableViewController.
Here is my code…….
In MLCViewController.h
//created protocol
#protocol MLCCancelDelegate;
#protocol MLCCancelDelegate <NSObject>
#optional
-(void)CancelMLCSession;
#end
#property(nonatomic,weak)id <MLCCancelDelegate>Mlcdelegate;
MLCViewController.m
//Which is written in a UIAlertView Delegate method
switch (buttonIndex) {
case 0:
{
if (self.Mlcdelegate && [self.Mlcdelegate respondsToSelector:#selector(CancelMLCSession)])
{
[self.Mlcdelegate CancelMLCSession];
}
break;
}
default:
break;
}
}
In TimeTableViewController.m
//ViewDidLoad
self.fifthViewController=[[MLCViewController alloc]init];
fifthViewController.Mlcdelegate = self;
//-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController* vc = [storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:vc];
pc.delegate = self;
[pc presentPopoverFromRect:rect inView:collectionData
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//Iam calling that delegate method like
-(void)CancelMLCSession{
NSLog(#"cancelling");
}
ADD this code
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
self.fifthViewController = [storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
pc = [[UIPopoverController alloc] initWithContentViewController:self.fifthViewController];
pc.delegate = self;
self.fifthViewController.Mlcdelegate=self;
Try putting
self. before fifthViewController.Mlcdelegate = self;
Try this,
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
MLCViewController* vc = (MLCViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MLCNote"];
vc.Mlcdelegate = self;
self.fifthViewController = vc;
//rest stuff
I am creating an iPad version of Master Detail Application using XCode 4.5 with ARC.
I have my iPadMaster.h/.m(as my master) and iPadDetailViewController.h/m(as my detail) set up.
I am trying to load different view controllers from iPadDetailViewController when users click/select the rows on iPadMaster.
I set this on iPadMaster.m at:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
iPadDetailViewController * DVC = [[iPadDetailViewController alloc]initWithNibName:nil bundle:nil];
DVC.itemNumber = indexPath.row;
}
and tried this stupid stunt on iPadDetailViewController.m on [viewDidLoad]:
switch(_itemNumber)
{
case 0:
{
//Detail row
vc1 *viewController = [[vc1 alloc] init];
[self presentViewController:viewController animated:YES completion:nil];
break;
}
case 1:
{
//Report row
vc2 *viewController = [[vc2 alloc] init];
//viewController.somePassedInData = theDataToPass;
[self presentViewController:viewController animated:YES completion:nil];
break;
}
case 2:
{
//Report row
vc3 *viewController = [[vc3 alloc] init];
//viewController.somePassedInData = theDataToPass;
[self presentViewController:viewController animated:YES completion:nil];
break;
}
...
case 9:
{
//Report row
vc9 *viewController = [[vc9 alloc] init];
//viewController.somePassedInData = theDataToPass;
[self presentViewController:viewController animated:YES completion:nil];
break;
}
default:
{
break;
}
On iPhone i would just plaster the 'switch cases' in the - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath but i'm at lost with iPad environment...
Thanx in advance...
The split view controller has a property, viewControllers. The object at index 1 is the detail controller. You should just create a mutable copy of viewControllers, replace the object at index 1 with your new controller, and set that array to be the split view's arrayControllers.
NextController *next = [[NextController alloc] init..... // or however you get your new controller
NSMutableArray *mut = [self.splitViewController.viewControllers mutableCopy];
[mut replaceObjectAtIndex:1 withObject:next];
self.splitViewController.viewControllers = mut;