我想要什么:在表格视图中显示一些数据列表。带空单元格的Tableview
通过创建不同的对象将数据存储在单个数组中。因此,对于每个对象,数组的大小都不相同。所以我的问题是显示数据,而不是完全填充表格单元格,一些单元格留空。它看起来不太好。
任何人都可以解释如何得到一个表视图没有任何额外的空单元格?
这是我如何安排数据:
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];
我想说明的tableview取决于哪个菜被选中里面这些成分列表。
这里是我的数据源方法
- (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;
}
将ü张贴的TableView的数据源方法? – 2013-03-14 09:48:38