0
私はループなどを試みましたが、何も動作していないようです。私はテキストフィールドを持っていて、一旦私はsaveを押すと、私はテーブルのセルにテキストを入れます。私がそれをやり直すと、前のエントリが置き換えられます。基本的に、配列に手動でObjectを追加しない限り、別のセルを追加できないようです。データは適切に引き出され、私はNSLogを使用し、データも保存されます。Objective-C、iOS、NSKeyedUnarchiver、1つのセルでのみデータを取得
私はこの問題は、どこかにここにあると思う:ここ
NSFileManager *filemgr;
NSString *docsDir;
NSArray *dirPaths;
filemgr = [NSFileManager defaultManager];
// Get the documents directory
dirPaths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
// Build the path to the data file
datafilePath = [[NSString alloc] initWithString: [docsDir
stringByAppendingPathComponent: @"data.archive"]];
tablesubtitles = [[NSMutableArray alloc]init];
tabledata = [[NSMutableArray alloc] init];
// Check if the file already exists
if ([filemgr fileExistsAtPath: datafilePath])
{
NSMutableArray *dataArray;
dataArray = [NSKeyedUnarchiver
unarchiveObjectWithFile: datafilePath];
titlestring = [dataArray objectAtIndex:0 ];
detailsstring = [dataArray objectAtIndex:1];
[tabledata addObject:titlestring];
[tablesubtitles addObject:detailsstring];
}
は、実際のテーブルのための他の方法である:
NSMutableArray *contactArray;
contactArray = [[NSMutableArray alloc] init];
[contactArray addObject:titlefield.text];
[contactArray addObject:detailstextfield.text];
[contactArray addObject:date ];
[NSKeyedArchiver archiveRootObject:
contactArray toFile:datafilePath];
を:私は、データを保存するよどこここ
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"];
if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homework"];
}
NSString *cellValue = [tabledata objectAtIndex:indexPath.row];
NSString *subtitle = [tablesubtitles objectAtIndex:indexPath.row];
cell.textLabel.text= cellValue;
cell.detailTextLabel.text= subtitle;
cell.textLabel.font = [UIFont systemFontOfSize:14.0];
cell.textLabel.backgroundColor = [ UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
// Configure the cell.
//-----------------------------------------START----------------------------Set image of cell----
cellImage = [UIImage imageNamed:@"checkboxblank.png"];
cell.imageView.image = cellImage;
//--------------------------------------------END---------------------------end set image of cell--
return cell;
}
です
あなたはどういう意味ですか? –
は完全なコードを提供し、セル生成のコード – NeverBe