3

コンソール ウィンドウで UITables indexPath.row をどのように出力しますか。どこにでも NSLog を追加したくありません。

「メンバーではありません」またはプロパティが表示され続けます。

(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 *'

行とセクションが 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) 
4

2 に答える 2

28

lldb がプロパティを認識していない場合は、いつでもアクセサ関数を使用できます。

print (NSInteger) [self.lastChangedIndexPath row]
于 2013-06-14T14:49:35.957 に答える
13

nsindexpath 変数をダブルタップし、次の要約形式を設定することで、Xcode の変数ウィンドウにインデックスパスを表示させることができます。

section:{(int)[$VAR section]},row:{(int)[$VAR row]}
于 2013-09-03T13:19:15.957 に答える