2017-03-03 51 views
0

我想要一個特定的部分indexPath,但這段代碼只給我第0部分indexPath,因爲InSection我設置了0. 如果有多個部分,那麼我怎麼得到indexPath獲取具有多個部分的行和部分的索引?

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0]; 

幫助我。

回答

0

如果單擊按鈕下面的代碼是非常有用的

-(IBAction)btnClicked:(id)sender 
{ 
    CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:tableviewName]; 

    NSIndexPath *indexPath = [self.accountTablView indexPathForRowAtPoint:buttonPosition]; 

    NSLog(@"section index-----%ld",(long)indexPath.section); 
} 
+0

感謝man..Its工作.. –

0

sender上的tag屬性正在返回它的默認值。
確保您sender創作過程中適當設置tag,應設置爲:

myView.tag = indexPath 

現在,sender而這樣做將返回正確的indexPath值:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0]; 

只是確保標記設置正確(我猜在cellForRowAtIndexpath :)來檢索正確的索引。