을 tableview textlabel
에 넣고 NSMutableArray(self.dateListArray)
을 detailtextlabel
에 같은 인덱스에 삽입합니다. 처음에 올바르게 추가되었지만 TableView
을 다시 열면 detailTextlabel
이 textlabel
으로되고 textlabel
이 detailTextlabel
이됩니다.두 개의 nsmutablearray 값이 서로 다른 값으로 바뀌고 있습니다.
나는 NSLog
모두 NSMutabelArray
이며 배열 값이 모두 바뀌고 있음을 알게되었습니다. 원래 값을 유지하는 방법? 제안에 대해 미리 감사드립니다. 은 왜 tableView == pdfListnameTable
을 확인하는있는 tableView 코드
- (void)viewDidLoad
{
if([[NSUserDefaults standardUserDefaults] objectForKey:@"children"] != nil)
{
self.tablePdfListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"children"]];
}
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"dates"] != nil)
{
self.dateListArray = [NSMutableArray arrayWithArray:[[NSUserDefaults standardUserDefaults] objectForKey:@"dates"]];
}
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
self.myPDFName = [NSString stringWithFormat:@"%@", [alertView textFieldAtIndex:0].text];
firstDayInYear = [NSDate date];
dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *currentTime = [dateFormatter stringFromDate:firstDayInYear];
NSLog(@"User's current time in their preference format:%@",currentTime);
if(!self. tablePdfListArray)
{
self.tablePdfListArray = [[NSMutableArray alloc]init];
}
if(!self.dateListArray)
{
self.dateListArray = [[NSMutableArray alloc]init];
}
[self.dateListArray insertObject:currentTime atIndex:0];
NSLog(@"mhy date dateListArray %@",dateListArray);
//the below if condition will not allow repeatative string array in tableList and textfield lenth.
if ([[alertView textFieldAtIndex:0].text length] != 0 && ![self.tablePdfListArray containsObject:self.myPDFName])
{
[self.tablePdfListArray insertObject:[NSString stringWithFormat:@"%@", [alertView textFieldAtIndex:0].text] atIndex:0];
NSLog(@"mhy date tablePdfListArray %@",tablePdfListArray);
NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.pdfListnameTable insertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
[defaults setObject:self.dateListArray forKey:[NSString stringWithFormat:@"children"]];
[defaults setObject:self.tablePdfListArray forKey:[NSString stringWithFormat:@"dates"]];
[defaults synchronize];
}
}}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(tableView == pdfListnameTable)
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone; //cell bg
//self.myChklist.backgroundColor = [UIColor clearColor];
}
NSString *tablePdfname = [self.tablePdfListArray objectAtIndex:indexPath.row];
cell.textLabel.text = tablePdfname;
NSString *tablePdfdate = [self.dateListArray objectAtIndex:indexPath.row];
//[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
cell.detailTextLabel.text = tablePdfdate;
return cell;
}
}
값이 바뀌는 것을 보여주는 나머지 부분은 어디에서입니까? –
cellForRowAtIndexPath 메소드에 대한 코드를 게시하십시오. – Girish
확인. 코드를 추가했습니다. –