所以我有一个自定义tableviewcells设置编程。我有4类自定义单元格,一个部分有一个自定义单元格。但我不知道这是错误的或不:iPhone - 以编程方式创建自定义TableView
(UITableViewCell *)tableView:(UITableView *)TheTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ShopsIdentifier = @"ShopsIdentifier";
static NSString *DescriptionsIdentifier = @"DescriptionsIdentifier";
static NSString *ServicesIdentifier = @"ServicesIdentifier";
static NSString *PartnersIdentifier = @"PartnersIdentifier";
if (indexPath.section == kShops) {
NSLog(@"Chargement cellule ShopDetailCell");
ShopDetailCell * shopshopCell = (ShopDetailCell *)[tableView dequeueReusableCellWithIdentifier:ShopsIdentifier];
if (shopCell == nil) {
shopCell = [[[ShopDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ShopsIdentifier] autorelease];
}
shopCell.detailController = self;
shopCell.shop = self.shop;
return shopCell;
}
if (indexPath.section == kDescriptions) {
NSLog(@"Chargement cellule DescriptionCell");
DescriptionCell * descriptionCell = (DescriptionCell *)[tableView dequeueReusableCellWithIdentifier:DescriptionsIdentifier];
if (descriptionCell == nil) {
descriptionCell = [[[DescriptionCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:DescriptionsIdentifier] autorelease];
}
descriptionCell.shop = self.shop;
return descriptionCell;
}
if (indexPath.section == kServices) {
NSLog(@"Chargement cellule ServicesCell");
ServicesCell * servicesCell = (ServicesCell *)[tableView dequeueReusableCellWithIdentifier:ServicesIdentifier];
if (servicesCell == nil) {
servicesCell = [[[ServicesCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ServicesIdentifier] autorelease];
}
servicesCell.shop = self.shop;
return servicesCell;
}
if (indexPath.section == kPartners) {
PartnersCell * partnersCell = (PartnersCell *)[tableView dequeueReusableCellWithIdentifier:PartnersIdentifier];
if (partnersCell == nil) {
partnersCell = [[[PartnersCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PartnersIdentifier] autorelease];
}
NSMutableDictionary * aPartner = [[NSMutableDictionary alloc] init];
aPartner = [shop.partners objectAtIndex:indexPath.row];
partnersCell.partner = aPartner;
[aPartner release];
return partnersCell;
}
return nil;
}
你可能会失去了'static'关键字。但它的工作?因为它看起来不错。 – mvds 2010-08-06 14:00:14
是的,它的工作。但是,当我想要将细胞排出或创建新细胞时,它会失败。 – 2010-08-09 07:50:17