Ambiguous reference to member 'tableView' - swift

Code and errors
Continued on the code and one more errors!
Hi, I'm new to Xcode swift. I have been doing good so far except trying to follow someone tutorial from 8.2 and I'm getting these errors that I have the hardest time understanding. Anybody who can explain what these errors means and maybe, just maybe how to fix them?
I have edited my posts, can't link more items than 2.

You need to declare your tableView up by your other #IBOutlets since you are using a UIViewController and putting a tableView within it's view. Currently the UIViewController doesn't know what tableView you are referring too.
#IBOutlet var tableView: UITableView!
Then link it up in the interface builder as you have done with your other #IBOutlets. Make sure you link the delegate and dataSource properties of your tableView back to the view controller as well.
To do the latter, after you select your tableView, select the Connections Inspector area, as shown in the picture below, and connect them back to your UIViewController.

In my case, I've used:
#IBOutlet private weak var tableView: UITableView!
and use tableView inside extensions method.
I've change private to fileprivate, and error has gone.

Here it is in Swift 4
let iPath = NSIndexPath(row: self.TableView.numberOfRows(inSection: 0)-1,
section: self.messageTableView.numberOfSections-1)
self.TableView.scrollToRow(at: iPath as IndexPath,
at: UITableViewScrollPosition.bottom,
animated: true)

Related

UITextView dataDetector is not working in tableViewCell

I have a UITextView in a TableViewCell and I wanted to enable data detection in the textView in order to show clickable links and Phone numbers.
So I did this in storyBoard
These steps didn't work so I did the same in code.
#IBOutlet weak var postDescTextView: UITextView!
override func layoutSubviews() {
super.layoutSubviews()
postDescTextView.isUserInteractionEnabled = true
postDescTextView.isSelectable = true
postDescTextView.dataDetectorTypes = .all
}
But none of the steps seems to work.
There is clearly something I'm doing wrong. I'm pretty sure the answer is a simple one. I've found some similar questions like these.
Question 1
Question2
But unlike these questions, I don't want my TextView editable nor I don't want to be able to select The TableViewCell. Just need to make the Datalink detection work in a TableViewCell.
If you're trying to make postDescTextView programmatically remove everything else and add the following.
postDescTextView.isEditable = false
postDescTextView.dataDetectorTypes = .all
Or if you have a storyboard
Note: If you're using the programmatic approach there is no need for giving it in viewDidLayout which gets called every time there's a layout change. Give it in the init method instead.

Cannot edit brand new UITextField

I just made a new Swift project, put some text fields and a couple buttons in it, and when I start the app I cannot seem to be able to edit the text fields. Like the text fields are not taking any input. Any of them!
At the moment this is my only code. There should be nothing wrong with it. I literally ran the same code on another app and everything worked perfectly.
#IBOutlet weak var monthlyTF: UITextField!
#IBOutlet weak var annualL: UILabel!
var year = Double()
#IBAction func calculateAnnB(_ sender: UIButton) {
if let monthlyInc = Double(monthlyTF.text!){
year = 12*monthlyInc
annualL.text = "\(year)"
}else{
annualL.text = "That's not a number!"
}
}
There are other buttons and text fields in the app but I have not linked them yet because I didn't get to that part. I just wanted to test it piece by piece. Should I link them all first and then try?
It should be a really simple project. I don't know why I keep getting stuck on stupid technicalities like these.
Try what dinosaysrawr said, and also make sure User Interaction Enabled is set to true in the storyboard (under "View" in the Attributes Inspector).
Try deleting and reinstalling the UITextField in the storyboard
Edit: Also, make sure that the textField is enabled in the "Attributes Inspector" under "Control". If it's not enabled, it'll be grayed out and you can't tap on it to edit it

Cannot invoke reloadData with no arguments UITableViewController

In my game app I'm having difficulty with my LobbyViewController (a list of available games to play). self.tableView.reloadData() is throwing an error Cannot invoke reloadData with no arguments. It's throwing this error because I have the LobbyViewController class inheriting from a custom BaseViewController for navigation. The problem goes away when I change it to inherit from UITableViewController, but then I don't get the custom navigation created with BaseViewController.
How can I get self.tableView.reloadData() to work when LobbyViewController inherits from BaseViewController?
Here is a gist of the relevant files:
https://gist.github.com/jtansley/2f8710b3cc410be1f715
Thanks!
It's ok that BaseViewController does not inherit from TableViewController. In which case you need an #IBoutlet reference to an actual UITableView in your LobbyViewController.
Drag your UITableView from the storyboard onto your LobbyViewController and then you should see
#IBOutlet weak var tableView: UITableView!
you should be able to call self.tableView.reloadData() without any issues.

Can't hook up an outlet collection in Xcode 6 using storyboard

I am having trouble creating an outlet collection in Xcode 6. Outlet collections in Xcode 6 now function as regular IBOutlets, and you use the same #IBOutlet attribute to declare an outlet collection while being sure to specify an array for the type. I have done this in my view controller's swift file i.e.
#IBOutlet var cardButtons: UIButton[]
In Xcode 5 when one control drags from an element in the storyboard to the corresponding view controller using the assistant editor they are presented with an option to create either an outlet or an outlet collection. This seems to no longer be possible in Xcode 6 and my guess is because outlets and outlet collection now share the same #IBOutlet attribute. How should I create an outlet collection which will contain say 10 buttons without being able to control drag each one from the storyboard view and hook it up to my
#IBOutlet var cardButtons: UIButton[]
property in my view controller swift file?
You've got it right, you just need to define the array more formally:
#IBOutlet var cardButtons: Array<UIButton>
Now you'll be able to connect the buttons from IB.
The above should work, but still doesn't in Xcode 6 beta 3. A workaround is to use an NSArray until Xcode and Swift can handle this properly:
class ViewController: UIViewController {
#IBOutlet strong var labels: NSArray!
override func viewDidLoad() {
super.viewDidLoad()
for label in self.labels as [UILabel] {
label.textColor = UIColor.redColor()
}
}
}
This is under the Xcode 6 beta known issues:
"Interface Builder does not support declaring outlet collections in Swift classes. (15607242)"
Nate Cook's answer is correct for attaching outlets, but not outlet collections. Hopefully in the next Xcode 6 beta release this issue will be resolved.
In seed 3 of Xcode 6, the following syntax works:
#IBOutlet strong var cardButtons: NSArray?
Note the following:
You have to use strong because #IBOutlet is weak by default, and since the array is not in the interface, it will vanish before you have a chance to use it.
You have to use NSArray because you can't mark Array as strong.
Knowing the contained type is now up to you, of course.
Note also that this is not the syntax advertised by the docs or by Xcode itself when you control-drag to form an outlet collection. I can't help that; using that syntax causes a seg fault, so clearly something else is needed, at least for now.
It is strange, I did IBOutlet with swift and it works for a while, Just realize it stop working and find out something get broke in last release of xcode beta where it is not working.

CellForRowAtIndexPath method not being called in storyboards

I am using storyboards for my app.In that I have a UITableViewController class.I am loading the UITableView from the data coming from the webservice. The issue is that the data is coming but is not geting populated in UITableView. On Decoding I found out that the cellForRowAtIndexPath method is not getting called.
Do we need to connect the datasource and delegate in storyboard as it was done in separate xibs before storyboard. And if so, where to connect the datasource and delegate methods as there is NO Filesowner in storyboard.
I am stuck up with this issue and any help would be appreciated.
Thanks
If you put a table view controller into a storyboard, it usually has the table view's dataSource and delegate already set up correctly. If yours turn out to be connected OK, the other possibility is that tableView:numberOfRowsInSection: is returning zero.
If you are using the UITableViewController, then you need to make the numberOfSections:tableView: data source method returns 1 instead of the default return of 0.
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1 // Default is 0, should be greater than 0
}