基本的には、一番上に追加できるリストビューを作成しています。これを行うための最善の方法は、UITableViewCell自体をNSMutableArrayに格納することです。これは、オブジェクト内のすべてのデータを含む配列からUITableViewCellを単純にプルできるため、このリストビューの長さが10セルを超えることはありません。
また、ストーリーボードを使用しているため、initWithCoderを使用していることにも注意してください。
次のコードは私が試しているものであり、機能しません。
// This is where my NSMutableArray is initialized:
- (id)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
if (!_CellsArray) {
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TestCell"];
_CellsArray = [NSMutableArray arrayWithObject:cell];
}
}
return self;
}
//UITableView Delegate & DataSource Methods
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TestCell"];
[_CellsArray insertObject:cell atIndex:0];
return [_CellsArray objectAtIndex:indexPath.row];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 10;
}
私はこれに間違った方法でアプローチしている可能性があることを認識しています、それが私がここにいる理由です:)
ありがとうございました。
編集:コードのタイプを修正しました(TimerCell-> UITableViewCell)