簡體   English   中英

分配節和行的索引路徑以准備prepareSeague

[英]Assign section and row indexpath to prepareForSeague

我正在嘗試為我的prepareForSeague獲取indexpath.sectionindexpath.row 我可以通過indexpath.row沒有問題,但是我正在努力將其與部分集成。 它會傳遞正確的數據,但是不會傳遞到第一部分之外,因為我不知道如何設置這些部分。

因此,基本上我也需要知道它所在的部分。

我看着objectsAtIndexes

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
dynamicDetailTableViewController *destViewController = segue.destinationViewController;
NSLog(@" indexPath row %d",indexPath.row);
NSLog(@" indexPath section %d",indexPath.section);

// Assume self.view is the table view
destViewController.titleString = [self.namesArray objectAtIndex: indexPath.row];
//Health
destViewController.healthArray = [self.healthArray objectAtIndex:indexPath.row];

編輯

更清楚地說,它確實可以工作,但是我有不同的部分,因此在第一部分之后,它沒有傳遞正確的值。 它僅傳遞正確的第一個Sections值,因為它僅基於行而不是基於section計算索引路徑。 我也需要它來計算截面,但不確定如何。

如果您有多個節和行,我想您的數據結構是錯誤的。 您的數據結構應如下所示

第一節

---->第1行

---->第2行

---->第3行

第二節

---->第1行

---->第2行

第三節

---->第1行

---->第2行

---->第3行

---->第4行

為了獲取值,您的代碼應類似於

[[self.array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

上面的代碼說給我特定section特定row

在您看來情況並非如此,您已將所有數據保存在單個數組中,因為它應該是array的數組。

您得到的值有誤,因為對於每個indexPath.section而言,indexPath.row均以0開頭,因此對於第1個部分而言,它可以正常工作,但對於其他部分而言,則不能。

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM