我花了最后3个小时在这个问题上挠头,因为一切似乎都正确,除了我无法通过我的tableviewcell类来设置uilabels在我的定制单元格。请求在customtableviewcell中加载成员错误,并设置其IBOUTLETS
这里是我的代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableViewCell" owner:self options:nil];
cell = (UITableViewCell *)[nib objectAtIndex:0];
//cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
//cell.imageViewSection =
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *textTitle = [[stories objectAtIndex: storyIndex] objectForKey: @"title"];
NSURL *imageurl = [NSURL URLWithString:[[stories objectAtIndex: storyIndex] objectForKey: @"description"]];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:imageurl]];
cell.imageViewSection = image;
cell.titleLabelText.text = textTitle;
return cell;
}
如果有人能帮助我走出这将是真棒:)
谢谢你的抬头。我在我名为TableViewCell的tableviewcell类中设置了iboutlets。 当谈到使用 cell.imageViewSection.image =图像 我得到一个请求成员的东西不是一个结构或联合... 定制细胞一旦对象被初始化我就应该能够设置它的值... – MrPink 2011-05-13 13:20:30
@MrPink - 啊,这是因为'UITableViewCell'没有你设置的属性。你需要强制转换。我延伸我的答案。水库神们的任何变化MrPink是你吗? – PeyloW 2011-05-13 13:30:52
@MrPink - 还使用“UINib”实例来创建单元格。这个想法是一样的,但'UINib'允许将nib文件缓存在内存中以加快创建速度。 – PeyloW 2011-05-13 13:35:41