如何在控制台窗口中打印出 UITables indexPath.row。我不想到处添加 NSLogs。
我不断收到“不是会员”或财产。
(lldb) expr (int) printf("%d \n",self.lastChangedIndexPath->_row)
error: 'NSIndexPath' does not have a member named '_row'
(lldb) print self.lastChangedIndexPath->_row
error: 'NSIndexPath' does not have a member named '_row'
(lldb) print self.lastChangedIndexPath->row
error: 'NSIndexPath' does not have a member named 'row'
(lldb) print self.lastChangedIndexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'
(lldb) po self.lastChangedIndexPath.row
error: property 'row' not found on object of type 'NSIndexPath *'
我认为因为 row 和 section 属于 UITableView 类别:
@interface NSIndexPath (UITableView)
+ (NSIndexPath *)indexPathForRow:(NSInteger)row inSection:(NSInteger)section;
@property(nonatomic,readonly) NSInteger section;
@property(nonatomic,readonly) NSInteger row;
@end
我什至创建了一个迷你测试应用程序并创建了一个名为 MyIndexPath 的 NSIndexPath 克隆,我可以使用以下命令正常访问它:
(lldb) print self.indexPath->_row
(NSInteger) $0 = 10
(lldb) print self.indexPath.row
(NSInteger) $1 = 10
(lldb)
测试应用
#import "ViewController.h"
#pragma mark -
#pragma mark CLONE OF NSIndexPath ===================================
#pragma mark -
//------ a clone on NSindexPath with same section and row properties
@interface MyIndexPath : NSObject
@property(nonatomic) NSInteger section;
@property(nonatomic) NSInteger row;
@end
@implementation MyIndexPath
@end
#pragma mark -
#pragma mark MAIN CLASS that has MyIndexPath as iVar =============================
#pragma mark -
@interface ViewController (){
NSString * _iVarString;
int _iVarInt;
}
@property (nonatomic, retain) NSString * propertyString;
@property (nonatomic ) NSInteger propertyInt;
@property (nonatomic, retain) MyIndexPath * indexPath;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//Set iVars
_iVarString = @"hello ivar";
_iVarInt = 34;
//Set properties (and synthesized ivars _propertyString and _propertyInt)
self.propertyString = @"my propertyString";
self.propertyInt = 46;
//Local vars
NSString * localString_ = @"hello";
int localInt_ = 10;
//------
self.indexPath = [[MyIndexPath alloc]init];
self.indexPath.section = 10;
self.indexPath.row = 10;
NSLog(@"PUT BREAKPOINT HERE");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
而且我可以很好地访问它——只是不在 UITableView 类别中。
(lldb) print self.indexPath->_row
(NSInteger) $0 = 10
(lldb) print self.indexPath.row
(NSInteger) $1 = 10
(lldb)