2013-03-17 53 views
0

這是我要的tableView的tableView不重用小區正確

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"CounterCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     [[NSBundle mainBundle] loadNibNamed:@"CounterCell" owner:self options:nil]; 
     cell = nibLoadedCell2; 
    } 

    Program *program = [memory getProgramAtIndex:[memory chosenProgram]]; 
    NSMutableArray *arrayOfIntervals = [[NSMutableArray alloc] init]; 
    arrayOfIntervals = program.arrayOfIntervals; 
    NSMutableDictionary *interval = [arrayOfIntervals objectAtIndex:indexPath.row]; 


    UITextField *intervalName = (UITextField *)[cell viewWithTag:1]; 
    intervalName.text = [interval objectForKey:@"nameOfInterval"]; 
    [intervalName addTarget:self action:@selector(returnKey:) forControlEvents:UIControlEventEditingDidEndOnExit]; 
    [intervalName addTarget:self action:@selector(editingEnded:) forControlEvents:UIControlEventEditingDidEnd]; 
    [intervalName addTarget:self action:@selector(editTextField:) forControlEvents:UIControlEventEditingDidBegin]; 

    timeInSeconds = [[interval objectForKey:@"timeInSeconds"] intValue]; 

    if (indexPath.row == 0) { 
     firstCellGeneralTime = timeInSeconds; 
    } 

    NSString *time = [self timeTextWithTimeInSeconds:timeInSeconds]; 

    UILabel *intervalTime = (UILabel *)[cell viewWithTag:2]; 
    intervalTime.text = time; 

    if (indexPath.row == 0) { 
     majorLabel.text = time; 
    } 

    UILabel *hourString = (UILabel *)[cell viewWithTag:11]; 
    hourString.text = [NSString stringWithFormat:@"%d",hoursInt]; 

    UILabel *minuteString = (UILabel *)[cell viewWithTag:12]; 
    minuteString.text = [NSString stringWithFormat:@"%d",minutesInt]; 

    UILabel *secondString = (UILabel *)[cell viewWithTag:13]; 
    secondString.text = [NSString stringWithFormat:@"%d",secondsInt]; 



    UIButton *editTime = (UIButton *)[cell viewWithTag:21]; 
    [editTime addTarget:self action:@selector(openPicker:) forControlEvents:UIControlEventTouchUpInside]; 




    return cell; 
} 

我的表視圖代碼顯示出比3個細胞少一個比特,並且在某點i刪除所述第一小區和比所述第四單元被示出向上。

問題是第4個單元格與我的第3個單元格完全相同,但它應該是不同的。

它確實重用它,因爲它應該。

我不知道我做錯了什麼。

這是一個細胞的刪除的代碼:

NSIndexPath *firstCellIndexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
NSArray *arrayOfIndexPath = [[NSArray alloc] initWithObjects:firstCellIndexPath, nil]; 
[atableView deleteRowsAtIndexPaths:arrayOfIndexPath withRowAnimation:UITableViewRowAnimationTop]; 
+0

什麼是'nibLoadedCell2' – 2013-03-17 08:04:28

+0

我正在使用的自定義單元格 – 2013-03-17 08:15:10

回答

0

你必須在刪除單元從program.arrayOfIntervals數組中刪除該第一interval

+0

我將其從arrayOfIntervals中移除。否則它會崩潰。 – 2013-03-17 08:14:37

+0

請將該代碼添加到您的問題。 – 2013-03-17 08:19:11

0

發現,有問題的代碼是:

Program *program = [memory getProgramAtIndex:[memory chosenProgram]]; 
NSMutableArray *arrayOfIntervals = [[NSMutableArray alloc] init]; 
arrayOfIntervals = program.arrayOfIntervals; 
NSMutableDictionary *interval = [arrayOfIntervals objectAtIndex:indexPath.row]; 

我創建一個新的方案,並從它那裏得到的時間間隔的細節,而不是使用程序我刪除從第一區間...

我覺得很愚蠢......

+0

刪除arrayOfIntervals = [[NSMutableArray alloc] init];從你的代碼。您正在分配一個數組,但是立即將變量設置爲其他值。 – 2013-03-17 08:32:28