[Solved] How to load Custom cell (Xib) in UITableview using Swift

import UIKit class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { //MARK:- Sample Data Array to load in TableView let sampleArrray: \[String\] = \[“val1”, “val2”, “val3”, “val4”, “val5”] //MARK:- Cell reuse identifier let cellReuseIdentifier = “cell” //MARK:- UITableView outlet @IBOutlet var tableView: UITableView! override func viewDidLoad() { super.viewDidLoad() // Registering the custom cell self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellReuseIdentifier) // Setting … Read more

[Solved] sendSynchronousRequest is deprecated in ios 9 [duplicate]

This is a working example, You should use NSURLSession, with Request. func testPost(sender: UIButton) { let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: NSURL(string: “http://localhost:8080/iOSServer/ios/helloworld/swiftCalculator”)!) request.setValue(“application/x-www-form-urlencoded”, forHTTPHeaderField: “Content-Type”) request.HTTPMethod = “POST” let d = “4” let data = “x=4&y=\(d)” request.HTTPBody = data.dataUsingEncoding(NSASCIIStringEncoding) let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in if let error = … Read more

[Solved] How do I capture screen view and share it? [closed]

You can add share button var shareButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: “shareButtonPressed:”) self.navigationItem.rightBarButtonItem = shareButton and populate share options func shareButtonPressed(sender: AnyObject) { NSLog(“shareButton pressed”) let stringtoshare: String = “This is a string to share” //add current screen shot image to share let imagetoshare = captureScreen() let activityItems: [AnyObject] = [stringtoshare, imagetoshare] … Read more

[Solved] how to encode this JSON reply from Food API

You have some response and this response’s value is most likely of type Data, so you need to decode it to some Swift type. Since Swift 4 you can easily use Decodable protocol for decoding Data to your custom model conforming to this protocol. So let’s create simple struct for simple json Json: let data … Read more

[Solved] ios UIView for complete viewController frame [closed]

-(UIView *) returnGradientView { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = view.bounds; //change your color as you like, I have used black and white gradient.colors = @[(id)[UIColor blackColor].CGColor, (id)[UIColor whiteColor].CGColor]; [view.layer insertSublayer:gradient atIndex:0]; return view; } Edit this will create an gradient view, upper side white … Read more

[Solved] Swift 4 need help to make triangle using (*)

Not quite equilateral but as close as you’re likely to get with character graphics. The main things are that you need an odd number of asterisks on each line for centering to work and you need to calculate an offset. (And, even so, you need output in a monospaced font for this to look right.) … Read more

[Solved] How to put the burger icon in a UIBarButtonItem?

You’ll want to use the UIBarButtonItem constructor init(image: UIImage?, style: UIBarButtonItemStyle, target: Any?, action: Selector?) an example usage would be: self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: “burger_icon”), style: .plain, target: self, action: #selector(self.someMethod)) In this example “burger_icon” is the name of the image asset in your project and self.someMethod is the method that is called when this … Read more

[Solved] Swift, Pass data from popover controller to previous controller [closed]

You can use custom delegate method to fill the value. class PopupviewController { weak var delegate: filleTextViewDelegate? func calldelegate () { delegate?.fillTextview(filledData) } } protocol filleTextViewDelegate : class { func fillTextview(filledData: String) } class CurrentViewController :filleTextViewDelegate { func fillTextview(filledData: String) { textView.text = filledData } } solved Swift, Pass data from popover controller to previous … Read more

[Solved] how to use two CollectionView on same view controller scroll one by one [closed]

You can add two collection view in a single view controller by dragging it. but you have to validate UIcollection view like func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { var cell = HomeCollectionViewCell() if(collectionView == self.collName1) { cell = collName.dequeueReusableCellWithReuseIdentifier(“CellIdentifier”, forIndexPath: indexPath) as! HomeCollectionViewCell } else if(collectionView == self.collName2) {} return cell } … Read more

[Solved] What is the use of the “of” keyword in Swift? [duplicate]

In this case, “of” is the label for the argument called “name”. If you were to call this function, it would be student(of: “Mathematics”) However inside the student function, you would get it’s value with “name” func student(of name: String) -> String { print(name) // TODO: Do something and return } Just a suggestion, IMHO … Read more