3

現在、ユーザーのプロフィールを表示するアプリを作成しています。そのために、さまざまな種類のデータ (電話番号、メール アドレスなど) 用のカスタム セルを含む UITableViewCell を使用しました。プロファイルごとに最大 8 つのセルがあります。

ユーザーは、最も簡単な方法でプロファイルを編集できます。テーブルビューの編集モードがトリガーされると、編集可能なすべてのラベルがテキストフィールドに置き換えられます。変更が完了したら、ラベルに戻ります。

Homever、見えない細胞に問題があるようです。それらがビューに再表示されるたびに、再読み込みされ、setEditing:YES メソッドが再びトリガーされます。このため、テキストフィールドで行われたすべての変更が失われます。

テーブルビューが非表示セルを削除して元に戻すのを防ぐ方法はありますか? セルは 8 つしかないので、リソースをそれほど消費することはなく、変更が行われるたびに状態を保存する必要もありません。

PS : dequeueReusableCellWithIdentifier メソッドと各セルの識別子を使用していくつかのことを試しましたが、目的を達成することができませんでした。セルを非表示にするたびに、その内容が更新されます。

4

2 に答える 2

3

動的ではなく静的セルを使用する必要があります。テーブル ビューを選択し、画像のように構成を変更します。 ここに画像の説明を入力

そしてインターフェースビルダーにセルを追加!

于 2014-07-27T10:56:46.313 に答える
1

この場合、UITableView の再利用性は役に立ちませんが (ほとんどの場合、再利用性はもちろん素晴らしいことです)、編集を保存するのは非常に困難です。そのため、再利用を避けることができ、事前に細胞を準備できます。

NSMutableArrayViewController にiVar またはプロパティを追加する

@property (nonatomic, strong) NSMutableArray *cells;

あなたのviewDidLoadで:cells何もせずに準備してくださいreuseIdentifier

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.


    //Creates tableView cells.
    [self createCells];

}

- (void)createCells
{
    self.cells = [NSMutableArray array];

    TCTimeCell *cellCallTime = [[TCTimeCell alloc] initWithTitle:@"CALL" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeCall];
    [_cells addObject:cellCallTime];

    TCTimeCell *cellLunchOut = [[TCTimeCell alloc] initWithTitle:@"LUNCH START" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeLunchOut];
    [_cells addObject:cellLunchOut];

    TCTimeCell *cellLunchIn = [[TCTimeCell alloc] initWithTitle:@"LUNCH END" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeLunchIn];
    [_cells addObject:cellLunchIn];

    TCTimeCell *cellSecondMealOut = [[TCTimeCell alloc] initWithTitle:@"2ND MEAL START" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeSecondMealOut];
    [_cells addObject:cellSecondMealOut];

    TCTimeCell *cellSecondMealIn = [[TCTimeCell alloc] initWithTitle:@"2ND MEAL END" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeSecondMealIn];
    [_cells addObject:cellSecondMealIn];

    TCTimeCell *cellWrapTime = [[TCTimeCell alloc] initWithTitle:@"WRAP" forTimecard:_timecard andTimeEntryType:TCTimeEntryTypeWrap];
    [_cells addObject:cellWrapTime];
}

この配列から tableView を設定できます。

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cells.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.cells[indexPath.row];
}

セクション化された tableView がある場合は、セルを として準備できますarray of arrays。その場合、データ ソース メソッドは以下のようになります。

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.cells count];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.cells[section] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    return self.cells[indexPath.section][indexPath.row];
}
于 2014-07-27T11:02:46.177 に答える