【发布时间】:2010-09-02 02:27:13
【问题描述】:
伙计们,我想在每个部分设置不同的子视图,我将不同的视图放入 NSMutableArray,所以我希望我可以根据 indexPath.section 访问它,这是我的代码:
for (int i =0; i<promoCount; i++) {
self.textView.text= [NSString stringWithFormat:@"text view :%d",i];
[self.arrayPromotions addObject:self.textView];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellPromotionIdentifier = @"cellPromo";
cell = [tableView dequeueReusableCellWithIdentifier:cellPromotionIdentifier];
if (cell==nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellPromotionIdentifier] autorelease];
}
[cell.contentView addSubview:[self.arrayPromotions objectAtIndex:indexPath.section]];
cell.contentView.layer.masksToBounds = YES;
cell.contentView.layer.cornerRadius = 5.0;
return cell;
}
但它不起作用,子视图只出现在最后一部分(但该子视图的内容是正确的)。
我确定该数组已被不同的视图填充(通过执行 NSLog)。
任何人都可以帮助我.????
【问题讨论】:
-
你的意思是第一部分的单元格没有出现子视图或者显示不正确?
-
是的,第一节的单元格没有出现子视图,但最后一节的单元格出现了子视图
标签: iphone objective-c uiview uitableview