第八章UItableView翻訳
2593 ワード
一、UItableViewはリストを表示するために使用され、選択、削除、再配置することができる.
二、UItableViewはUItableViewDataSourceとUItableViewDelegateインタフェースの補助クラスを実現する必要があり、これらはUItableViewControlで実現されている.
三、UItableView Controlインスタンスを作成し、そのloadViewにUItableViewを作成する
四、BNRitemStore model
1.単一インスタンスを使用してBNRitemStoreオブジェクトを作成する
2,メソッドにstaticオブジェクトを直接作成することで,オブジェクトを回収できない.
static BNRItemStore *sharedStore = nil;
3、データは内部に開放し、外部に閉鎖する
五、UItableViewデータソース
1,UItableView表示の場合、少なくともそのdataSourceにtableView:numberOfRowsInSection:and tableView:cellForRowAtIndexPath:を要求する必要がある.
2,
六、UItableViewCells
1,adapter,itemのviewを返す
2、デフォルトのcellはすでにレイアウトを提供しており、必要に応じて希望のレイアウトを選択することができます.
3 dataSourceのtableView:cellForRowAtIndexPath:を使用してcellを返します
七、cellの再利用
1、cellを再利用し、メモリのクラッシュを避ける必要があります
2、cellプールがあり、cellをキャッシュします.
3、複数のタイプのcellがある場合、エラータイプのcellが得られる可能性があり、避ける方法はcellにタイプを設定することである.
二、UItableViewはUItableViewDataSourceとUItableViewDelegateインタフェースの補助クラスを実現する必要があり、これらはUItableViewControlで実現されている.
三、UItableView Controlインスタンスを作成し、そのloadViewにUItableViewを作成する
四、BNRitemStore model
1.単一インスタンスを使用してBNRitemStoreオブジェクトを作成する
2,メソッドにstaticオブジェクトを直接作成することで,オブジェクトを回収できない.
static BNRItemStore *sharedStore = nil;
3、データは内部に開放し、外部に閉鎖する
@property (nonatomic, readonly) NSArray *allItems;
- (NSArray *)allItems
{
<span style="white-space:pre"> </span>return self.privateItems; // get , ios , ; array copy immutable
}
@property (nonatomic) NSMutableArray *privateItems;
- (instancetype)initPrivate
{
self = [super init];
if (self) {
_privateItems = [[NSMutableArray alloc] init]; //
}
return self;
}
五、UItableViewデータソース
1,UItableView表示の場合、少なくともそのdataSourceにtableView:numberOfRowsInSection:and tableView:cellForRowAtIndexPath:を要求する必要がある.
2,
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [[[BNRItemStore sharedStore] allItems] count];
//section ,
}
六、UItableViewCells
1,adapter,itemのviewを返す
2、デフォルトのcellはすでにレイアウトを提供しており、必要に応じて希望のレイアウトを選択することができます.
3 dataSourceのtableView:cellForRowAtIndexPath:を使用してcellを返します
七、cellの再利用
1、cellを再利用し、メモリのクラッシュを避ける必要があります
2、cellプールがあり、cellをキャッシュします.
3、複数のタイプのcellがある場合、エラータイプのcellが得られる可能性があり、避ける方法はcellにタイプを設定することである.
<span style="font-family: Arial, Helvetica, sans-serif;">- (UITableViewCell *)tableView:(UITableView *)tableView</span>
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{<pre name="code" class="objc">// Get a new or recycled cell
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"forIndexPath:indexPath];NSArray *items = [[BNRItemStore sharedStore] allItems];BNRItem *item = items[indexPath.row];cell.textLabel.text = [item description];return cell;}
4,在TableViewController的viewDidLoad中,向tableview注册cell
- (void)viewDidLoad { [super viewDidLoad]; [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"]; }