2012-04-16 24 views
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/capturedcran20120416142.png

感谢您的时间

+0

是不是要'addInfo'覆盖第一个呼叫第二个电话? – trojanfoe 2012-04-16 12:32:01

+0

不应该是一个不同的细胞? – Hosni 2012-04-16 12:54:24

+0

@Nit已经指出,您需要某种*逻辑*来确定填充单元的方式 - 您对所有单元总是做同样的事情,因此您看到了结果。 – trojanfoe 2012-04-16 12:57:08

回答

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"]; 
+0

这实际上只适用于这种情况,但不是当我使用时:[cell addInfo: @“journal 1”: @“description 1”: @“01/02/2012”: @“second.png”]; [cell addInfo: @“journal 2”: @“description 2”: @“01/02/2012”: @“second.png”]; – Hosni 2012-04-16 12:45:28

+0

U将获得重复的数据,因为第二次调用会覆盖第一个数字 – DivineDesert 2012-04-16 12:46:44

+0

@Hosni另一种选择是在字典中添加数据并将其添加到数组中,因此必须给出objectAtIndex valueForkey。所以它会按照数组索引显示数据。 – 2012-04-16 12:58:42

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; 

} 

希望,它会帮助你......寒

相关问题