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];
}
}
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];
}
UIStoryboard *view3 = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
View3ViewController *view_3 =[view3 instantiateViewControllerWithIdentifier:#"view3_id"];
[self.navigationController presentViewController:view_3 animated:YES completion:nil];
You can load storyboard file
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
and load controller from storyboard:
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"myViewController"];
and present this controller
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
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];
*/
I want to pass data between storyboard with tabBar and external xib .
I tried to use prepareforsegue but the method didn't call or if i define a segue this didn't recognize this .
my code is :
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"<identifier>"];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];
// [self performSegueWithIdentifier:#"try" sender:self]; // tried to use performSegueWithIdentifier but this recognize identifier
and the prepareforsegue method code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
BIDViewController *viewControllerView = segue.destinationViewController;
viewControllerView.isViewPushed=1;
NSLog(#"prepareForSegue");
Instead of this:
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"<identifier>"];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];
Try this:
UIStoryboard *storyborad = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
BIDViewController *view = [storyborad instantiateViewControllerWithIdentifier:#"myIdentifier"];
view.isViewPushed = 1;
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController pushViewController:view animated:YES];
I am using MFSideMenu in my app which have 4 UIScrollViews with the same code I am using the same exact code in this tutorial in 4 different UIViewControllers which added as subviews whenever they're chosen form the SideMenuViewController and that is the code I am using to do that
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1 //or any Index) {
UIViewController *centerController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"centerController"];
UIViewController *secondController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"secondController"];
[centerController.view addSubview:secondController.view];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
NSArray *controllers = [NSArray arrayWithObject:centerController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
} }
The problem here is that the the view controllers don't show any images they show the UIScrollView background, though and when I test them separated in another application they work
After searching for a few hours I didn't find the solution anywhere, but I managed to fix it myself.
The problem happened because I shouldn't have used addSubView and should have used my new view controller as a UINavigationController instead.
Like this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 1 /*or any Index*/) {
UIViewController *centerController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"centerController"];
UIViewController *secondController = [[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"secondController"];
//Now we no longer need this-->[centerController.view addSubview:secondController.view];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
//Edit starts here
NSArray *controllers = [NSArray arrayWithObject:secondController];
//Edit ends here
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed]; }
}