1

qrコードをスキャンするプロジェクトを行っています。このプロジェクトには、ユーザーのスキャンの履歴を表示する必要がある履歴ページがあります。URLのみが含まれています。そこで、彼が以前にスキャンしたURLのリストをテーブルビューに表示することを計画しています。

履歴リストを保存するにはどうすればよいですか?助けてください。NSMutable配列などを使用して、スキャンしたURLを次のように保存できますか[myArray writeToURL:aURL atomically:NO];

4

3 に答える 3

0
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingString:@"/"];
NSString *fullPathToFile = [filePath stringByAppendingPathComponent:@"myfile.plist"];
[myArray writeToFile:fullPathToFile atomically:YES];
于 2011-12-23T09:38:28.433 に答える
0

はい、できます。

テーブルビューは、テーブルビューのソースとしてNSMutableArrayを使用するためにUITableViewDataSourceを実装する必要があります:(ここでは、このサンプルコードの配列としてmyArrayを使用しています)

-(void)saveToHistoryArray:(NSString *)urlAsString {
    [myArray addObject:urlAsString];
    [self.tableView reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
/* insert error checking here */

    return [myArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [myArray objectAtIndex:indexPath.row];

    return cell;
}
于 2011-12-23T06:40:24.313 に答える
0

はい、これにはsqliteまたはcoredataを使用して内部データベースを作成する必要があります。ユーザーがqrcodeストアをデータベースにスキャンし、ユーザーが履歴を確認したい場合は、データベースからフェッチして、表示に使用するメソッドを表示します。

于 2011-12-23T07:17:52.767 に答える