私が欲しいもの:テーブルビュー内にデータのリストを表示します。
データは、異なるオブジェクトを作成することにより、単一の配列内に格納されます。したがって、オブジェクトごとに、配列のサイズは異なります。だから私の問題は、データを表示しているときに、テーブルのセルを完全に埋めるのではなく、一部のセルが空のままになっていることです。見栄えがよくありません。
空のセルを追加せずにテーブル ビューを取得する方法を説明できる人はいますか?
データを整理する方法は次のとおりです。
Recipe *recipe1 = [Recipe new];
recipe1.ingredients = [NSArray arrayWithObjects:@"1. Fish - 500 g .",@"2. Onion (Big) - 2 nos (Chopped)",@"3. Garlic (Chopped) - 3 flakes",@"4. Green chillies - 2 nos (Chopped)",@"5. Chilly powder - 3/4 tbsp ",@"6. Coriander powder - 1/2 tsp ",nil];
Recipe *recipe2 = [Recipe new];
recipe2.ingredients = [NSArray arrayWithObjects:@"1. fish - 300 gm",@"2. Tomato(medium) - 1 no",@"3. Garlic - 10 gm",@"4. Coconut powder - 10 gm",@"5. Curry leaves - A few",@"6. Salt - As reqd",@"7. Onions(medium) - 2 nos(chopped)",@"8. Oil - 1 - 2 tbsp",nil];
選択した料理に応じて、これらの食材リストをテーブルビュー内に表示したいと考えています。
これが私のデータソースメソッドです
- (NSInteger)numberOfSectionsInTableView:(UITableView *)aTableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryNone;
}
[cell.textLabel setFont:[UIFont fontWithName:@"Bold" size:20]];
// Configure the cell.
cell.textLabel.text =[data objectAtIndex:indexPath.row];
return cell;
}