2013-03-17 55 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