我有7 sections
一个UITableView
(周一至周五),并在每个部分的标题上添加按钮,并在第一部分的标题上添加一个“重复所有天”按钮,单击此按钮会将第一部分下的内容重复到所有其他部分。单击添加按钮将导航到另一个视图以添加当天的时间段。现在我面临的问题是,如果我首先为星期一添加了一个时间段,它会正确地添加到第一部分。然后我单击“重复所有天”按钮并将这个时间段复制到所有其他天。同样,如果我在其他任何一天添加任何其他时间段,(意味着如果我在星期二再添加一个时间段),这将在所有其他日期重复。为什么会这样?这就是我正在做的事情。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
NSArray *sectionContents = [[self contentsList] objectAtIndex:[indexPath section]];
NSString *contentForThisRow = [sectionContents objectAtIndex:[indexPath row]];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=contentForThisRow;}
在我contentslist array
的每天有 7 个数组,在添加时隙后调用 done 方法,它是这样的:
- (IBAction)doneAction:(id)sender
{
if(sectionNumber==0)
{
if (![Listfor_monday containsObject:time])
{
[Listfor_monday addObject:time];
}
}
//tuesday
else if(sectionNumber==1)
{
if (![Listfor_tuesday containsObject:time])
{
[Listfor_tuesday addObject:time];
}
}
//wednesday
else if(sectionNumber==2)
{
if (![Listfor_wednesday containsObject:time])
{
[Listfor_wednesday addObject:time];
}
}
//thursday
else if(sectionNumber==3)
{
if (![Listfor_thursday containsObject:time])
{
[Listfor_thursday addObject:time];
}
}
//friday
else if(sectionNumber==4)
{
if (![Listfor_friday containsObject:time])
{
[Listfor_friday addObject:time];
}
}
//saturday
else if(sectionNumber==5)
{
if (![Listfor_saturday containsObject:time])
{
[Listfor_saturday addObject:time];
}
}
//sunday
else if(sectionNumber==6)
{
if (![Listfor_sunday containsObject:time])
{
[Listfor_sunday addObject:time];
}
}
}
但是新添加的项目被复制到所有数组中。任何人都可以帮忙吗?