How to show necessary methods to be implemented for specific protocol - xcode

I am absolute beginner with IOS and XCode and swift and I am doing my first tries with Xcode in a Yosemite built in a Vmware running under Windows7 (guest is MAC yosemite, Host is windows running vmware workstation 9 )
I have a ViewController Class in my IOS project declared as follow:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {...}
Now I would like to implement the necessary methods of the protocols UIViewController and UITableViewDelegate.
In a tutorial
http://jamesonquave.com/blog/developing-ios-apps-using-swift-tutorial/
it says I have to use Command+Click on a protocoll to show which methods should be implemented.
I don't know howto do "command+click on the protocoll" this with my vmware.
any hints ?
When using Alt+clicking on a protocoll it shows me the help. If I am WindowsButton+clicking on a protocoll it opens a new window with sourcecode of the protocoll. Now howto show methods, which should be implemented.

To help you out, UIViewController is a class, which you are subclassing. It is not a protocol, so it doesn't have any necessary methods for you to implement. You can however override the methods you inherit, which is what you see in when you first create the file, ex.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
This overrides the method you inherited from UIViewController. If you aren't doing anything other than calling super.viewDidLoad() you can remove the entire function from your code.
Now UITableViewDataSource and UITableViewDelegate or both protocols, so they may or may not have required methods to implement.
What you describe when you alt-click, is the same as if you right clicked on UITableViewDataSource and selected jump to definition. This is what you get when you command click on an actual Mac. What the tutorial is saying is that the required methods will be at the top, which isn't always the case if you look at the documentation (as the methods are organized more by purpose there). In the case of UITableViewDataSource, you should see something like:
protocol UITableViewDataSource : NSObjectProtocol {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
optional func numberOfSectionsInTableView(tableView: UITableView) -> Int // Default is 1 if not implemented
optional func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? // fixed font style. use custom view (UILabel) if you want something different
optional func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?
You will notice that the first two methods func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int and func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell do not have optional in front of them. This means that these are the required methods for this protocol. The optional ones below that are optional.
In the case of UITableViewDelegate you'll see that there are no non-optional methods, and therefore it does not require you to implement any.

You are doing the right thing when you windows click the protocol name to jump to its definition, which is basically just a list of all its methods you can copy and paste into your code
Edit
the below is for changing keyboards:
You could try swaping the keys like this:
I don't like putting external source links because they sometimes dissapear so below is the text in their how to:
To swap the Option/Alt key and the Command/Windows key:
Fusion 2.x and later
Go to VMware Fusion > Preferences.
Click Keyboard & Mouse, and then Key Mappings.
Find the line that has a Mac Shortcut of Option,
and double-click it to edit it.
If you don't see this line, click the + button and then select
Option in the top row of keys.
In the To mapping in the bottom row of keys ensure that Alt is not
slected and that the Windows logo is selected.This will ensure that
pressing the Option key will send the Windows key to the virtual
machine.
Click OK.
Find the line that has a Mac Shortcut of the
command key logo, and double-click it to edit it.
If you don't see this line, click the + button and then select the
command key logo in the top row of keys.
In the To mapping in the bottom row of keys ensure that the Windows
logo is not selected and that Alt is selected.This will ensure that
pressing the Command key will send the Alt key to the virtual
machine. Click OK.
Fusion 1.x
Shut down your virtual machine and quit Fusion.
Navigate to [Macintosh HD]//Library/Preferences/VMware Fusion
Ctrl-click the config file and select Open with.
Select TextEdit and click Open. Add the line:
-mks.keyboard.swapAlt = TRUE
When your virtual machine starts, the Option/Alt key and the Command/Windows key are reversed.

Related

NSTableView Delegate Methods aren't getting called by .reloadData()

This one is stumping me, though I know it's going to be simple.
I have multiple ViewControllers, each of which has a table view to display a list of data specific to the controller. Three out of the 4 work perfectly. However, I'm clearly missing something in the forth, because the Delegate methods are never getting called by .reloadData(). No compiler errors, just never calls my delegate methods for some reason.
Here is my class setup including my connected outlet variable:
class performanceViewController: NSViewController, NSTableViewDataSource, NSTableViewDelegate {
//--------------------------------
// OUTLET CONNECTIONS
//--------------------------------
#IBOutlet weak var displayPerformanceList: NSTableView!
I've also implemented the following two delegate functions:
func numberOfRows(in tableView: NSTableView) -> Int {
and
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
but for some reason, neither of these functions are called when I execute my custom function:
func redrawViews() {
self.displayPerformanceList.reloadData()
}
(Note: the .reloadData is wrapped in a function because it will be doing other things as well that I haven't added in yet.)
I added breakpoints in both of the delegate functions, which is how I know they are not getting executed.
I know this is going to turn out to be something stupid that I missed since I have it working in three other custom viewControllers... I just can't for the life of me figure out what I missed...
Any thoughts would be greatly appreciated!
:)
Well, after poking around a bit more and following some tutorials, I found my problem. I completely forgot to link the NSTableView Data Source and Delegate to the controller in the Interface Builder!
Doh!
Leaving this question/answer here in case anyone else gets caught by this. :)

display rowActions in NSTableView OS X

I want to create a swipable tableview same as it is present in the IOS. But I am not able to find any document related to that. Also I was going through the NSTableView Documentation and fund the following.
/* View Based TableView: rowActionsVisible can be queried to determine if the "row actions" (see: tableView:rowActionsForRow:edge:) are visible or not. Set rowActionsVisible=NO to hide the row actions. Setting rowActionsVisible=YES is currently not supported and will throw an exception. This property is not encoded in the nib.
*/
#property BOOL rowActionsVisible NS_AVAILABLE_MAC(10_11);
At the end of the Comment it says Setting rowActionsVisible=YES is currently not supported and will throw an exception. So, how are we going to set the action?
Any leads would be appreciated.
So the new Swipeable table functionality was added in MacOS 10.11, and it looks like the way to do it is via implementing the NSTableViewDelegate method:
optional func tableView(_ tableView: NSTableView, rowActionsForRow row: Int, edge edge: NSTableRowActionEdge) -> [NSTableViewRowAction]
Where you can set up NSTableViewRowAction objects via a relatively straightforward init method.

Trigger an action from a TableviewCell in swift

I'm new to Swift and I'd like know how to trigger an action when a cell in my TableviewController is tapped. I created the configuration of my tableview completely in the Storyboard, so the cells were not created manually by coding. I also edited the tag-field of this cells in order to address them, but I am wondering how.
Do I have to create a new class or is it possible to write the code in the basic viewcontroller.swift - class?
I just would like to know how such Events are handled in Swift and how I can catch them and react on them.
Thank you very much for answering.
Just add this code to your UITableViewController.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
//In here do whatever you want to do when the user selects a row
}

Setting a Variable "as" a Class

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("HeaderCell") as! CustomHeaderCell
You can see the code above. I just wanted to ask that how and why we can, or should, set a tableViewCell as a Class? In this case it is CustomHeaderCell. For further info about the code here's the thing: I am just creating a custom header by following a guide I saw in web.
You should use this pattern when (a) you know the actual class of the object being returned, whereas the compiler can't reasonably know this; and (b) you need to then use the methods/properties of this subclass.
In this case, you probably have a cell prototype in your storyboard that specifies a CustomHeaderCell base class (or you have registered a class or NIB such that you know that the HeaderCell identifier will return a CustomHeaderCell instance). Furthermore, you presumably want to reference the properties of this CustomHeaderCell (e.g. setting the text property of its custom UILabel outlets or whatever).

Xcode swift method completion does not promoted anything after stroke the [tab] key

Despite so much advantages of swift lang, one of the reason I did not adopt swift code is its bad code completion support with Xcode.
Here are two scenarios to better describe my question.
Scene 1:
During daily app development, I may come across quite a few protocol methods. Take the following UITableViewDataSource method
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
for example, after typing
func tableView(tableView: UITableView,
, I will normally type [tab] key, but there are nothing to promote in swift lang.
while things go smoothly in Objective-C:
So most of the cases, I have to jump to UITableView(wait a 1-2 secs for Xcode to generate swift header), and copy the method needed, then paste it the place I was coding.
By the way, if you [command + left] the method pasted above, Xcode has no idea what the function is, and where it is defined.
Scene 2:
To tweak animation, I need to change a method to an alternative one with more args.
//from
class func animateWithDuration(duration: NSTimeInterval, animations: () -> Void)
//to
class func animateWithDuration(duration: NSTimeInterval, animations: () -> Void, completion: ((Bool) -> Void)?)
In Objective-C, I gonna stroke [tab] before the last closing parenthesis, everything works fine. When I do this in swift, just a tab(four blanks) will appear.
My questions are:
How do you accomplish the two scenes I described above?
Are there some better way to do the same job for swift?(Maybe a plugin available out there, or any other helpful tips)
This is something I also despise while writing code in swift. There is no great way to do this, therefore you have to choose your method before you let it autocomplete.
For both scenario 1 and 2, you would have to type the first letters of tableView and animateWithDuration respectively, and use the up and down arrows to choose your method, and hit tab to finish the entire method.
The plus of swift is that it will automatically fill in func or class func, but after you fill in the methods, you can't add or remove parameters.
So far I can't find an easier way to do this. You'll have to wait for apple to improve their autocomplete.

Resources