2013-03-12 34 views
0

我有一個分段tableview,其中段數和行數是動態的。數據從不同的數組和字典中分配給每一行。我想通過得到當前行之前的任何部分中的任何行的行數,當調用didSelectRowAtIndexPath時。我跟着this answer,但給出了錯誤的結果。 我想應該有一種方式來獲得一個線性計數...在分段tableview中對行進行線性計數

回答

0

我找到了解決辦法: 在- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 我說:

NSString *numberOfRowsInSectionString = [[NSString alloc]initWithFormat:@"Section%i",section]; 
      [numberOsRowsArray addObject:numberOfRowsInSectionString]; 

當我需要知道的行數我是:

NSString *currentSectionString = [[NSString alloc]initWithFormat:@"Section%i",indexPath.section]; 
    [numberOsRowsArray sortUsingSelector:@selector(compare:)]; 
    NSUInteger indexOfTheObject = [numberOsRowsArray indexOfObject:currentSectionString]+indexPath.row;