Ios 使用单独的单元格而不是单独的数组
在Big Nerd Ranch的书:-iOS编程(第三版)中,Ch9第205页有一个铜牌挑战。我们必须显示2个部分,1个显示项目>和其他项目为什么不先检查价格,然后退出(或创建)相应的表格单元格? 像这样:Ios 使用单独的单元格而不是单独的数组,ios,uitableview,Ios,Uitableview,在Big Nerd Ranch的书:-iOS编程(第三版)中,Ch9第205页有一个铜牌挑战。我们必须显示2个部分,1个显示项目>和其他项目为什么不先检查价格,然后退出(或创建)相应的表格单元格? 像这样: - (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath { NSLog(@"hello"); static NSString *CellIde
- (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
{
NSLog(@"hello");
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";
UITableViewCell* cell = nil;
NRItem *p= [[[BNRItemStore sharedStore] allItems] objectAtIndex:indexPath.row];
if (indexPath.section==0)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:[p description]];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
[[cell textLabel] setText:[p description]];
}
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"hello");
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UITableViewCell *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
//Configure the cell...
if (!cell) {
cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
if (!cell2) {
cell2= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
BNRItem *p= [[[BNRItemStore sharedStore] allItems] objectAtIndex:indexPath.row];
if([p value] >50)
{
[[cell textLabel] setText:[p description]];
}
else{
[[cell2 textLabel] setText:[p description]];
}
if (indexPath.section==0) {
return cell;
}
else{
return cell2;
}
}
- (UITableViewCell*) tableView:(UITableView*) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath
{
NSLog(@"hello");
static NSString *CellIdentifier = @"Cell";
static NSString *CellIdentifier2 = @"Cell2";
UITableViewCell* cell = nil;
NRItem *p= [[[BNRItemStore sharedStore] allItems] objectAtIndex:indexPath.row];
if (indexPath.section==0)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[[cell textLabel] setText:[p description]];
}
else
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
[[cell textLabel] setText:[p description]];
}
return cell;
}