I have 7 sections
in a UITableView
(Monday to Friday), and add button on every section's header and a "repeat to all days" button on first section's header,clicking on this button will repeat the contents under first section to all other sections. Click on add button will navigate to another view to add a time slot for that day. Now the issue I am facing is that, if I first added a time slot for monday, it is added correctly to the first section. Then I clicked the "repeat to all days" button and copied this time slot to all other days. Again if I add any other time slot to any other day, (means if I add one more time slot to Tuesday) this is repeated in all other days. Why this is happening? This is what I am doing.
- (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;}
In my contentslist array
I have 7 arrays for each day, after adding the time slot a done method is called and it is like this:
- (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];
}
}
}
But the newly added item is copied to all arrays. Can anyone help?
Listfor_Monday
, etc., as an array of lists,doneAction:
wouldn't need to test seven different cases. – Marcelo Cantos May 26 '13 at 9:27