2013-02-04 34 views
0
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
    } 

// NSLog(@"msgcnt123 %@\n",[messageCount objectAtIndex:indexPath.row]); 

    NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:@"@"]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
// NSLog(@"key %@\n",[[clist allKeys]objectAtIndex:indexPath.row]); 

    cell.textLabel.text = [seperateArray objectAtIndex:0]; 
// cell.textLabel.text = [contactlist objectAtIndex:indexPath.row]; 
    cell.selectionStyle = UITableViewCellSelectionStyleNone; 

// NSLog(@"sep %@\n",seperateArray); 


    if (![[seperateArray objectAtIndex:1] isEqualToString:@"0"]) { 
     NSLog(@"msgCount %@\n",[seperateArray objectAtIndex:1]); 
     lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)]; 
     lblCnt.backgroundColor = [UIColor lightGrayColor]; 
     lblCnt.textColor = [UIColor blackColor]; 
     lblCnt.text = [seperateArray objectAtIndex:1]; 
     lblCnt.textAlignment = UITextAlignmentCenter; 
     lblCnt.layer.masksToBounds = YES; 
     lblCnt.layer.cornerRadius = 2.0f; 
     [cell.contentView addSubview:lblCnt]; 

    } 
    else 
    { 
     NSLog(@"msgCount1 %@\n",[seperateArray objectAtIndex:1]); 
     [lblCnt removeFromSuperview]; 
     lblCnt.hidden = YES; 
    } 

    return cell; 
} 

我已经添加在每一行中的标签,其显示的信息数received.In didSelect方法消失我让标签计数零,所以我可以从多于一排的情况下tableView.In消失标签在表格视图标签中不会消失。的UILabel不UITableView的

+0

你想要什么..我不明白 – iPatel

+0

clist是什么,它包含什么,seperateArray的价值是什么。 – Dilip

+0

clist是nsmutable dictionary.value in separatearray:aa 1,bb 2,cc 2 – user2003416

回答

1

简单的和肮脏的方法来达到ü想要的是使用标签

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

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

if (cell == nil) { 
    cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
} 

NSArray *seperateArray = [[clist objectForKey:[[clist allKeys]objectAtIndex:indexPath.row]]componentsSeparatedByString:@"@"]; 

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
cell.textLabel.text = [seperateArray objectAtIndex:0]; 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 

if (![[seperateArray objectAtIndex:1] isEqualToString:@"0"]) { 

    lblCnt = [[UILabel alloc]initWithFrame:CGRectMake(260, 13, 20, 20)]; 
    lblCnt.backgroundColor = [UIColor lightGrayColor]; 
    lblCnt.textColor = [UIColor blackColor]; 
    lblCnt.text = [seperateArray objectAtIndex:1]; 
    lblCnt.textAlignment = UITextAlignmentCenter; 
    lblCnt.layer.masksToBounds = YES; 
    lblCnt.layer.cornerRadius = 2.0f; 
    [cell.contentView addSubview:lblCnt]; 

    //Add a tag 
    lblCnt.tag = 1000; 


} 
else 
{ 
    /* 
    NSLog(@"msgCount1 %@\n",[seperateArray objectAtIndex:1]); 
    [lblCnt removeFromSuperview]; 
    lblCnt.hidden = YES; 
    */ 


    for (UIView *view in [cell.contentView subviews]) { 

     if (view.tag == 1000) { 
      [view removeFromSuperview]; 
     } 

    } 

} 

return cell; 
} 

,并选择基于标签的视图。

+0

感谢code.it工作正常。 – user2003416

相关问题