2009-08-14 2 views
2

в приложении iphone.Как получить IndexPath

Я пытаюсь получить значение indexPath.row, чтобы что-то сделать на основе строки, выбранной в программно созданной таблице.

Может кто-нибудь скажет мне, почему значение indexPath.row не подходит. Это что-то вроде 21487 ... 3?

NSUInteger nSections = [myTableView numberOfSections]; 
NSUInteger nRows = [myTableView numberOfRowsInSection:nSections]; 
NSIndexPath *indexPath = [NSIndexPath indexPathForRow: nRows inSection:nSections]; 
NSLog(@"No of sections in my table view %d",nSections); 
NSLog(@"No of rows in my table view %d",nRows); 
NSLog(@"Value of selected indexPath Row %d", indexPath.row); 

Благодаря, Aaryan

ответ

7

Строки и участки с NSIndexPath являются массивами, и так начинаются в 0, а не 1. Следовательно, число строк (или секции) в NSIndexPath на самом деле 1 больше индекса последнего.

Попробуйте

NSInteger lastSection = nSections - 1; 
NSInteger lastRow = nRows - 1;  
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:lastRow inSection:lastSection]; 
Смежные вопросы