2012-06-25 134 views
-5

我使用自定义样式的UITableView我在故事板中有一个红色警告(未分类编译失败)。iOS自定义UITableView单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"Cell"]; 

    codeLabel.text = [[courseMURArray objectAtIndex:indexPath.row] objectForKey:@"courseCode"]; 
    nameLabel.text = [[courseMURArray objectAtIndex:indexPath.row] objectForKey:@"courseName"]; 
    houreLabel.text = @"3"; 
    priceLabel.text = @"0.000"; 

    return cell; 
} 
+4

您能否让您的问题更清楚?我不太明白你在问什么。 – pasawaya

+0

如果您回答自己的问题,请在答案区域添加答案。 –

回答

2

试试看这样的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"YourCell"; 
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) 
    { 
     cell = [[UITableViewCell alloc]init]; //or some other init, don't have a Mac nearby, don't remember it by heart 
    } 

    self.codeLabel.text = [[courseMURArray objectAtIndex:indexPath.row] objectForKey:@"courseCode"]; 
    self.nameLabel.text = [[courseMURArray objectAtIndex:indexPath.row] objectForKey:@"courseName"]; 
    self.houreLabel.text = @"3"; 
    self.priceLabel.text = @"0.000"; 

    [cell addSubview:self.codeLabel]; 
    [cell addSubview:self.nameLabel]; 
    [cell addSubview:self.houreLabel]; 
    [cell addSubview:self.priceLabel]; 

    return cell; 
} 

希望它可以帮助