2012-07-10 29 views
6

Tôi có một ứng dụng Iphone trong đó tôi kết hợp hai mảng và hiển thị trong cùng một vấn đề table.the ở đây là tôi không thể thay đổi vị trí của nhãn văn bản chi tiết trong ô.đây là đoạn mã của tôi 'thay đổi vị trí của detailtextlabel trong ô?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell_with_arrow.png"]]; 
     [cell setBackgroundView:img]; 
     [img release];   
    } 
    if(newssarray==nil||[newssarray count]==0) 
    {    
    } 
    else 
    { 
     NSDictionary *dicttable=[newssarray objectAtIndex:indexPath.row]; 
     head=[dicttable objectForKey:@"news"]; 
     head1=[dicttable objectForKey:@"name"]; 
     NSString *sub=[dicttable objectForKey:@"created"]; 

     NSLog (@"%@",head); 

     [[cell viewWithTag:12] removeFromSuperview]; 
     [[cell viewWithTag:13] removeFromSuperview]; 
     [[cell viewWithTag:14] removeFromSuperview]; 

     UIButton *shopLabel=[self buttonWithText:head andFrame:CGRectMake(49, 12, 250,5)] ; 
     shopLabel.tag=12; 
     //shopLabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin; 
     [shopLabel addTarget:self action:@selector(openRestaurantsList) forControlEvents:UIControlEventTouchUpInside]; 

     UIButton *shopLabel1=[self buttonWithText:head1 andFrame:CGRectMake(49, 12, 250,5)] ; 
     shopLabel1.tag=14; 
     //shopLabel.autoresizingMask=UIViewAutoresizingFlexibleRightMargin; 
     [shopLabel1 addTarget:self action:@selector(openRestaurantsList) forControlEvents:UIControlEventTouchUpInside]; 
     cell.detailTextLabel.frame = CGRectMake(49, 30, 150,5); 
     if(indexPath.row < [newsseperatearray count]) 
     { 
      UIImage *cellImage = [UIImage imageNamed:@"news.png"]; 
      cell.imageView.image = cellImage; 
      //NSStringEncoding encoding=NSASCIIStringEncoding; 
      cell.imageView.frame=CGRectMake(0,0,48,48); 
      cell.imageView.bounds=CGRectMake(0,0,48,48); 
      [cell.imageView setClipsToBounds:NO]; 
      NSLog(@"%@",sub);      
      cell.detailTextLabel.text = sub; 
      cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
     } 
     else 
     { 
      UIImage *cellImage = [UIImage imageNamed:@"menu_icon.png"]; 
      cell.imageView.image = cellImage; 
      //NSStringEncoding encoding=NSASCIIStringEncoding; 
      cell.imageView.frame=CGRectMake(0,0,48,48); 
      cell.imageView.bounds=CGRectMake(0,0,48,48); 
      [cell.imageView setClipsToBounds:NO]; 
     } 
     [cell addSubview:shopLabel]; 
     [cell addSubview:shopLabel1]; 
     // [cell addSubview:shopLabel2]; 
    } 
    return cell; 
} 

'ai cũng có thể giúp tôi đạt được điều này?

Trả lời

7

Tạo lớp con UITableViewCell, giữ kiểu ô đó là UITableViewCellStyleSubtitle và ghi đè layoutSubviews trong phân lớp đó. Sau đó, bạn có thể thay đổi khung của detailTextLabel (chỉ cần đảm bảo gọi phương thức triển khai siêu thực hiện là layoutSubviews theo phương pháp của bạn).

Các vấn đề liên quan