我的网络服务中有一些产品。我从中获取产品名称并使用标签文本在我的表格视图中显示它。我明白了。现在我的问题是,当我在我的表格视图中选择一些产品时,我的标签会重新加载并用我现有的标签文本覆盖,即使我的 didselectrowatindexpath 是空的。这个我用过
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
bookName = [[UILabel alloc]initWithFrame:CGRectMake(100, 3, 180, 25)];
NSString *text = [NSString stringWithFormat:@"%@",[[stories objectAtIndex:indexPath.row] objectForKey: @"product_name"]];
bookName.text = text;
bookName.textAlignment = UITextAlignmentCenter;
bookName.lineBreakMode = UILineBreakModeWordWrap;
[bookName setTextColor:[UIColor blackColor]];
CGSize expectedLabelSize = [text sizeWithFont:bookName.font constrainedToSize:bookName.frame.size lineBreakMode:UILineBreakModeWordWrap];
CGRect newFrame = bookName.frame;
newFrame.size.height = expectedLabelSize.height;
bookName.frame = newFrame;
bookName.numberOfLines = 0;
[bookName sizeToFit];
[cell.contentView addSubview:bookName];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}