NSIndexPath? does not have a member name 'row' error in Swift
You can either unwrap the optional indexPath
parameter with if let...
:
if let row = indexPath?.row {
cell.textLabel.text = self.dataStore[row]
}
or if you're sure indexPath
isn't nil
, you can force the unwrapping with !
:
cell.textLabel.text = self.dataStore[indexPath!.row]
Just keep in mind that indexPath!
on a nil value will be a runtime exception, so it's better practice to unwrap it as in the first example.
Xcode 6.3.2 Swift 1.2 NSIndexpath does not have member 'row'
You need to import UIKit
.
section
, row
and item
are properties of NSIndexPath
added by UIKit.
https://developer.apple.com/library/prerelease/ios//documentation/UIKit/Reference/NSIndexPath_UIKitAdditions/index.html
NSIndexPath does not recognize item, section, or row as properties
Do not use the getter/setter dot syntax, use brackets:
po (int)[index row]
po (int)[index section]
Note that the (int)
is necessary to print the row/section as an integer rather than a hex. Other such useful formatting parameters for LLDB can be found here.
EDIT
The Swift overlay to the Foundation framework provides the IndexPath structure, which bridges to the NSIndexPath class. The IndexPath value type offers the same functionality as the NSIndexPath reference type, and the two can be used interchangeably in Swift code that interacts with Objective-C APIs. This behavior is similar to how Swift bridges standard string, numeric, and collection types to their corresponding Foundation classes.
po index.row
po index.section
work as expected. The comment on p
vs. po
still stands.
It is worth noting that you may use IndexPath
in Swift instead of NSIndexPath, as described in the Apple Documentation.
How to access NSIndexPath section value?
You are access the section value correctly. You are just print it the wrong way.
section
have type of NSInteger
, which is Int
in swift
just change log to NSLog("Index Path Section %d", indexPath.section)
It print (null)
because the section value is 0
. and crashed when it is 1
because it is not valid object pointer
Getting the Row for Section indexPath in a tableView
Hi this is enough try and let me know if you face any issues...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
NSArray * nameArray = [self.sectionsArray objectAtIndex:indexPath.section];
PFUser *user = (PFUser*)[nameArray objectAtIndex:indexPath.row];
// PFUser *user = (PFUser*)[self.friends objectAtIndex:indexPath.section];
if (cell.accessoryType == UITableViewCellAccessoryNone)
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[self.recipients addObject:user.objectId];
NSLog(@"added:%@",user);
}
else {
cell.accessoryType = UITableViewCellAccessoryNone;
[self.recipients removeObject:user.objectId];
NSLog(@"removed:%@",user);
}
// this is enough
}
Swift xcode error: Row.Type has no subscript members
use: let filename = rows[indexPath.row].FileName
as opposed to accessing via a key.
Also, generally properties are declared camel case starting lower, ie: fileName
and quartzImage
Does not have a member named
If you get this as a compile error, then DetailViewController does not define a property called url.
If you get the error during execution, then the destinationViewController is not a DetailViewController. Set a breakpoint and check what type it really is.
UITableViewCell?' does not have a member named 'textLabel'
I am following the same tutorial, so I can feel your pain! :) In the tutorial the fellow has you delete and recreate the view controller, only then he forgets to mention that you need to name your view controller again. Any way, to save some aggravation, just create a new project, drop a Table View into the view controller, right click on the Table View, and link dataSource, delegate, and view to the View Controller.
Next, here is the code that works for me as of XCode 6.1. God knows what they are going to change next. But in short, you don't need the '?' after textLabel.
import UIKit
class ViewController: UIViewController, UITableViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
var items = ["test 1", "test 2", "test 3", "test 4"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 4
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
cell.textLabel.text = self.items[indexPath.row]
return cell
}
}
Hope that helps.
Related Topics
Open Uiimagepickercontroller in Landscape Mode
How to Upload Multiple Image on Firebase Using Swift
What Is the Use of Singleton Class in Objective-C
Type 'Nsattributedstringkey' (Aka 'Nsstring') Has No Member 'Font'
Didbegincontact Is Being Called Multiple Times for the Same Skphysicsbody
Swift: How to Draw Shapes and Detect Whether They Intersect
Statusbar Overlapping Content in iOS7
Cannot Invoke 'Indexof' with an Argument List of Type '(Checklistitem)'
Offline Crash Reporting in Crashlytics
How to Hide a Bar Button Item for Certain Users
How to Determine File Size on Disk of a Video Phasset in iOS8
iOS Ibeacon: How to Get All of Proximityuuid Programmatically
How to Disable Qlpreviewcontroller Print Button
iOS 10.3 Beta 3 Doesn't Persist Data of Keychainitem
Segues Initiated Directly from View Controllers Warning in Storyboard Xcode