logo
Tags down

shadow

Passing data between two view controllers in a tab controller


By : Herbert Tamayo Valer
Date : October 15 2020, 08:10 AM
should help you out Using Delegate Pattern
First create protocol for your Items class
code :
protocol ItemsDelegate {
    func newItemAdded()
}
class Items {

    var delegate: ItemsDelegate?

    static let shared = Items()
    var array = [Item]() {
        didSet {
           delegate?.newItemAdded()
        }
    }

}
override func viewDidLoad() {
    ...
    Items.shared.delegate = self
}
class SecondViewController: UIViewController, ItemsDelegate {
    ...
    func newItemAdded() {
        items = Items.shared.array
    }
    ...
}


Share : facebook icon twitter icon

Passing Data between View Controllers : from uitableview to a details view controller


By : Chris
Date : March 29 2020, 07:55 AM
I hope this helps you . For demo purpose, I will assume we have two view controllers ListViewController and DetailViewController. ListViewController has tableview and you have created a segue between your tableview cell and details view controller.
I'm assuming you are naming it as 'DetailSegue'. Your storyboard should look similar to the below image.
code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if ([segue.identifier isEqualToString:@"DetailSegue"]) {
    DetailViewController *detailVC = (DetailViewController*)segue.destinationViewController;
    NSIndexPath *indexPath = [self.tableView indexPathForCell:(UITableViewCell *)sender];
    detailVC.title = [self.source objectAtIndex:indexPath.row];
  }
}
#import <Foundation/Foundation.h>

@interface RecipeListViewController : NSObject

@property (weak, nonatomic) NSString *title;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end
@implementation RecipeListViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.titleLabel.text = self.title;
}
@end

Passing messages to children of contained container view controllers from a custom container view controller?


By : Pavel Mandogus
Date : March 29 2020, 07:55 AM
Hope that helps After giving it some more thought and experimenting for a bit, I came up with a third approach: categories. It's still not as generic as I'd like, but a step up from what I had before and no longer reliant on subclassing built-in container controllers.
For my specific needs, I wanted a tab bar controller to forward the delegate message to its selected view controller. I created a category on UITabBarController called MessageForwarding with an implementation of the correct method signature. The category method just forwarded the identical call to self.selectedViewController, returning the result.

Passing VALUE between 2 View Controllers in SplitView Controller


By : avais
Date : March 29 2020, 07:55 AM
it should still fix some issue If you're doing a segue from one controller to the next, passing values can be as easy as adding this bit of code in your ViewController1 implementation:
code :
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    QuerySubmission * viewController2 = segue.destinationViewController;
    if(viewController2)
    {
        viewController2.location=[pickerViewArray objectAtIndex:selectedIndex];
    }
}

Two UIView Controllers - changing View controllers - touching top of Second View Controller changes back to first view c


By : binosebasti
Date : March 29 2020, 07:55 AM
hop of those help? This was due to the transition style being "Partial Curl". Changing this resolved the issue.

Passing Data between view Controllers Using a segue from a view embedded in a navigation controller to a tabbarcontrolle


By : Ahad Ali
Date : March 29 2020, 07:55 AM
this will help This is my view controller where you can check that I am sending 5 to tabbar first viewcontroller:
code :
   class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.performSegue(withIdentifier: "segueIdentifier", sender: self)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let barViewControllers = segue.destination as! UITabBarController
        let destinationNv = barViewControllers.viewControllers?[0] as! UINavigationController
        let destinationViewController = destinationNv.viewControllers[0] as! FirstViewController
        destinationViewController.currentBalance = 5
    }
}
class FirstViewController: UIViewController {

    var currentBalance = 0
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print(currentBalance)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
Related Posts Related Posts :
  • Displaying button at the end of onboarding flow on swift
  • How to disable swipe back gesture globally in ionic 4 angular project
  • RxSwift: Reacting to different cell types
  • Register for notifications (FCM) outside AppDelegate
  • How do I save the background color using Swift?
  • iOS: didCompleteWithError, didReceive Response not triggered with URLSession.uploadTask
  • How can I create multiple relationships between the same entities in Coredata?
  • Issue with unwrapping [String] when using image cache
  • Swift and Xcode: How to Build and Run a GitHub repository of iOS Application?
  • Handing a completion with CloudKit
  • Update Uitableview cells button title
  • How to handle multiple text fields effectively in UITextField's shouldChangeCharactersIn
  • NativeScript RadListView component template
  • UITableViewCell constraints breaking when adding a new cell
  • How to implement a listener or while(true) to stop a waveform plot from scrolling once recorder has finished recording i
  • problem with attributed text for keyboard titleBarButton when using IQKeyBoardManager
  • iOS: Extract detected numbers and links from UITextView?
  • Does iOS/UIKit have built in support for scheduling scroll like dinging
  • Drawing directions from google map api
  • Bottom corners arent round
  • Keep original node lighting after using a light for another node
  • How to calculate proper keyboard contentInset for UIScrollView inside of a modally presented form sheet UIViewController
  • update key values of NSManagedObjects safely
  • Why would Xcode show MUCH more memory use than Instruments for SceneKit app?
  • iOS Drawer UI that only works when breakpoint inserted
  • 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' when inserting a row i
  • Problem when attempting to loop AVPlayer (userCapturedVideo) seamlessly
  • Accessing information within a NSDictionary
  • Importing and Using a Swift SnapshotTesting Framework with Carthage
  • How do I swap the first and second items in an array of strings?
  • How to soften begin and endUpdates in TableView
  • Proper way to create geometry base view in code
  • PDF to Base64 on Ionic 3 app for Android and iOS platforms
  • PWA-Icon not used by iOS Devices
  • UICollectionView dynamic header size calculation
  • How best to remove all UIViewcontrollers and goto a single UIViewController?
  • How to generate Google Place API session token?
  • Thread 1: Fatal error: NSArray element failed to match the Swift Array Element type
  • How to get all custom tableview cell textField and textView value outside tableView
  • How do I fix, App Store Rejected app for external tester: Reason: Performance: App Completeness?
  • Validate Alamofire Response for both HTTP 200 and 500 status codes
  • Sorting array of date from newest to oldest in Swift 4
  • How to check existing versions in Test Flight
  • Execute Completion Handler in DispatchGroup
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org