1

我想向我的 customCell.m 添加一个方法,它允许我在一行中添加有关单元格的信息,所以我添加了:

 -(void) addInfo:(NSString*) pTitre:(NSString*) pDescritption:(NSString*) pDate: (NSString*)pImage
{
    [[self titre] setText:pTitre];
    [[self description] setText:pDescritption];
    [[self date] setText:pDate];
    [[self couverture] setImage:[UIImage imageNamed:pImage]];
}

但是当我在 mytableview.m 中调用该方法时,如下所示:

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3 ;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = @"firstviewcustomcellCell";

firstviewcustomcellCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

if (cell == nil)
{
    NSArray *topLevelObject=[[NSBundle mainBundle] loadNibNamed:@"firestViewCell" owner:nil options:nil];

            for(id currentObject in topLevelObject)
            {
                if([currentObject isKindOfClass:[firstviewcustomcellCell class]])
                {
                    cell=(firstviewcustomcellCell*) currentObject;
                    break;
                }
            }    
}
    [cell addInfo:
     @"journal 1":
     @"description 1":
     @"01/02/2012":
        @"second.png"];

    [cell addInfo:
     @"journal 2":
     @"description 2":
     @"01/02/2012":
     @"second.png"];

    return cell;

}

这就是它所显示的:

http://img213.imageshack.us/img213/2346/capturdcran20120416142.png

感谢您的时间

4

2 回答 2

0

您不能一次添加所有单元格信息...您必须一次添加一个单元格信息...如果您想添加所有单元格信息一次添加而不是放置条件...就像..

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 3 ;
}

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
 {
  static NSString *MyIdentifier = @"firstviewcustomcellCell";

   firstviewcustomcellCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

   if (cell == nil)
 {    
  NSArray *topLevelObject=[[NSBundle mainBundle] loadNibNamed:@"firestViewCell" owner:nil options:nil];

        for(id currentObject in topLevelObject)
        {
            if([currentObject isKindOfClass:[firstviewcustomcellCell class]])
            {
                cell=(firstviewcustomcellCell*) currentObject;
                break;
            }
        }    
   }



if(indexPath.row == 1)
 {
  [cell addInfo:
 [NSString stringWithFormat:@"journal 1"]:
 [NSString stringWithFormat:@"description 1"]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];
}
  else if(indexPath.row == 2)
 {

  [cell addInfo:
  [NSString stringWithFormat:@"journal 2"]:
 [NSString stringWithFormat:@"description 2"]:
 [NSString stringWithFormat:@"01/02/2012"]:
 @"second.png"];
 }

return cell;

 }

希望,它会帮助你......冷静

于 2012-04-16T12:40:52.223 回答
0
[cell addInfo:
 [NSString stringWithFormat:@"journal 1"]:
 [NSString stringWithFormat:@"description 1"]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];

[cell addInfo:
 [NSString stringWithFormat:@"journal 2"]:
 [NSString stringWithFormat:@"description 2"]:
 [NSString stringWithFormat:@"01/02/2012"]:
 @"second.png"];

请注意这部分代码。那里没有条件。

而是这样做

[cell addInfo:
 [NSString stringWithFormat:@"journal %i", indexpath.row]:
 [NSString stringWithFormat:@"description %i", indexpath.row]:
 [NSString stringWithFormat:@"01/02/2012"]:
    @"second.png"];
于 2012-04-16T12:36:01.143 回答