我在組(分區)模式下有UITableView
。該表的每個部分都包含約5個單元格。 表中的每個單元由一個UILabel
和一個UICollectionView
組成。 UICollectionView
將包含一組具有水平滾動的簡單項目。UICollectionView裏面的UITableView不正確的行
所以,我有類似網格視圖,它看起來在故事板,如:
在它看起來像模擬器:
的問題,我可以」我知道:
當我滾動任何行水平 - 一些另一行(可能是在同一個或另一個部分)可以與第一個同步滾動,看起來他們之間有一些連接,或者它是相同的UICollectionView
!
如何在每個UITableViewCell
中使用不同的UICollectionView
或打破「奇怪的連接」?
我的代碼(報頭):
@interface ipAthleteHistoryTableViewController : UIViewController <UICollectionViewDataSource, UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *datesRangeFromPeer;
@property (weak, nonatomic) IBOutlet UITextField *datesRangeToPeer;
@property (weak, nonatomic) IBOutlet UITableView *history;
- (IBAction)datesRangeFromPeerEditingExited:(id)sender;
- (IBAction)datesRangeFromPeerSet:(id)sender;
- (IBAction)datesRangeToPeerEditingExited:(id)sender;
- (IBAction)datesRangeToPeerSet:(id)sender;
- (IBAction)todaySpeedButtonPressed:(id)sender;
- (IBAction)weekSpeedButtonPressed:(id)sender;
- (IBAction)monthSpeedButtonPressed:(id)sender;
- (IBAction)quarterSpeedButtonPressed:(id)sender;
@end
實現:
- (void)viewDidLoad
{
_dumbNumberOfItems = 24;
_dumbNumberOfItems2 = 5;
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _dumbNumberOfItems2;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _dumbNumberOfItems;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 5;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"12.09.2014:%ld", (long)section];
}
- (UITableView *)findParentTableView:(UITableViewCell *)tableCellView
{
return (UITableView *)[ipNavigationHelper findParentViewOfClass:[UITableView class]
ofChildView:tableCellView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ipAthleteHistoryTableCell *cell = [tableView dequeueReusableCellWithIdentifier:athleteHistoryChart_ExcerciseTrialsCell forIndexPath:indexPath];
[[cell excerciseTitle] setText:[NSString stringWithFormat:@"Title %li:%li; %ld", [indexPath section], (long)[indexPath row], (long)[cell excerciseTrials]]];
[[cell excerciseTrials] reloadData];
return cell;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
ipAthleteHistoryExcerciseTrialCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:athleteHistoryChart_TrialCell
forIndexPath:indexPath];
ipAthleteHistoryTableCell *upCell = [self findParentTableCell:collectionView];
[[cell actualTrial] setText:[ipNumeralsConverter convertToLatinArabNumber:[indexPath row]]];
[[cell actualRepeats] setText:[NSString stringWithFormat:@"%li", [[[self findParentTableView:upCell] indexPathForCell:upCell] section]]];
[[cell targetRepeats] setText:[NSString stringWithFormat:@"%li", [[[self findParentTableView:upCell] indexPathForCell:upCell] row]]];
[[cell workWeight] setText:[NSString stringWithFormat:@"%li", [indexPath row]*10]];
return cell;
}
所有的初始工作(如ID的登記,細胞原型等)使用故事板完成的。
這個問題可能是findParentTableCell,但我看不到代碼。遍歷視圖層次結構總是有風險的,因爲事情可能會在版本之間發生變化,並且它不是很好的設計。如果我是你,我將創建一個數據模型類,並使該類實現集合視圖委託,然後在cellForRowAtIndexPath中,您可以簡單地將單元的集合視圖的委託分配給適當的數據模型對象 – Paulw11 2014-09-02 22:21:52