2011-12-06 8 views
2

は、私はこれを行うべきか、私のテーブルビューにラベルを追加したいですか?UILabel

私はテーブルビューの各行の4つのラベルを追加したい。.. いくつかのいずれかが、このためのコードを書く方法を私に説明できます。

+4

をサイト。より具体的にしてください。 –

+1

は、私にはかなり具体的なようです。ポスターが望んだことを正確に知っていれば、おそらく質問する必要はありません。 –

答えて

2

follwoingメソッドを実装し、

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [self getCellContentView:CellIdentifier]; 
    } 

    UILabel *lblManuName1 = (UILabel *)[cell viewWithTag:1]; 
    UILabel *lblManuName2 = (UILabel *)[cell viewWithTag:2]; 

    UILabel *lblCmpnyName1 = (UILabel *)[cell viewWithTag:3]; 
    UILabel *lblCmpnyName2 = (UILabel *)[cell viewWithTag:4]; 


     lblManuName1.text = @"Lbl 1" ; 
    lblManuName2.text = @"Lbl 2" ; 
    lblManuName2.text = @"Lbl 3" ; 
    lblCmpnyName2.text = @"Lbl 4" ; 

    return cell; 
} 

- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier { 

    CGRect CellFrame = CGRectMake(0, 0, 250, 30); 

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; 

    CGRect LabelManuName1Frame; 
    CGRect LabelManuName2Frame ; 

    CGRect LabelCmpnyName1Frame; 
    CGRect LabelCmpnyName2Frame; 

    LabelManuName1Frame = CGRectMake(10, 5, 75, 15); 
    LabelManuName2Frame = CGRectMake(59, 5, 205, 15); 

    LabelCmpnyName1Frame = CGRectMake(10, 22, 100, 15); 
    LabelCmpnyName2Frame = CGRectMake(59, 22, 205, 15); 



    if (orientation == UIInterfaceOrientationLandscapeLeft || 
     orientation == UIInterfaceOrientationLandscapeRight) { 

     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
      //LabelManuName1Frame = CGRectMake(10, 13.5, 180, 15); 
      //LabelManuName2Frame = CGRectMake(59, 13.5, 580, 15); 
      LabelManuName1Frame = CGRectMake(10, 5, 70, 30); 
      LabelManuName2Frame = CGRectMake(80, 5, 350, 30); 

      //LabelCmpnyName1Frame = CGRectMake(410, 13.5, 235, 15); 
      //LabelCmpnyName2Frame = CGRectMake(459, 13.5, 580, 15); 
      LabelCmpnyName1Frame = CGRectMake(435, 5, 70, 30); 
      LabelCmpnyName2Frame = CGRectMake(505, 5, 350, 30); 

     }else{ 
      LabelManuName1Frame = CGRectMake(10, 5, 75, 15); 
      LabelManuName2Frame = CGRectMake(59, 5, 370, 15); 

      LabelCmpnyName1Frame = CGRectMake(10, 22, 130, 15); 
      LabelCmpnyName2Frame = CGRectMake(59, 22, 370, 15); 
     } 

    } else { 
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { 
      //LabelManuName1Frame = CGRectMake(10, 13.5, 180, 15); 
      //LabelManuName2Frame = CGRectMake(59, 13.5, 300, 15); 
      LabelManuName1Frame = CGRectMake(10, 5, 70, 30); 
      LabelManuName2Frame = CGRectMake(80, 5, 250, 30); 

      //LabelCmpnyName1Frame = CGRectMake(370, 13.5, 205, 15); 
      //LabelCmpnyName2Frame = CGRectMake(419, 13.5, 200, 15); 
      LabelCmpnyName1Frame = CGRectMake(330, 5, 70, 30); 
      LabelCmpnyName2Frame = CGRectMake(400, 5, 250, 30); 
     }else { 
      LabelManuName1Frame = CGRectMake(10, 5, 75, 15); 
      LabelManuName2Frame = CGRectMake(59, 5, 205, 15); 

      LabelCmpnyName1Frame = CGRectMake(10, 22, 100, 15); 
      //Increse width of LabelCmpnyName2Frame 
      LabelCmpnyName2Frame = CGRectMake(59, 22, 205, 15); 
     } 
    } 



    UILabel *lblTemp; 

    UITableViewCell *cell = [[[UITableViewCell alloc] initWithFrame:CellFrame reuseIdentifier:cellIdentifier] autorelease]; 

    //Initialize Label with tag 3. 
    lblTemp = [[UILabel alloc] initWithFrame:LabelManuName1Frame]; 
    lblTemp.tag = 1; 
    //lblTemp.font = [UIFont fontNamesForFamilyName:@"Arial"]; 
    lblTemp.font = [UIFont fontWithName:@"Arial-BoldMT" size:13]; 
    lblTemp.backgroundColor = [UIColor clearColor]; 
    [cell.contentView addSubview:lblTemp]; 
    [lblTemp release]; 

    //Initialize Label with tag 4. 
    lblTemp = [[UILabel alloc] initWithFrame:LabelManuName2Frame]; 
    lblTemp.tag = 2; 
    //lblTemp.font = [UIFont fontNamesForFamilyName:@"Arial"]; 
    lblTemp.font = [UIFont fontWithName:@"Arial-BoldMT" size:13]; 
    lblTemp.backgroundColor = [UIColor clearColor]; 
    [cell.contentView addSubview:lblTemp]; 
    [lblTemp release]; 

    //Initialize Label with tag 5. 
    lblTemp = [[UILabel alloc] initWithFrame:LabelCmpnyName1Frame]; 
    lblTemp.tag = 3; 
    //lblTemp.font = [UIFont fontNamesForFamilyName:@"Arial"]; 
    lblTemp.font = [UIFont fontWithName:@"Arial-BoldMT" size:13]; 
    lblTemp.backgroundColor = [UIColor clearColor]; 
    [cell.contentView addSubview:lblTemp]; 
    [lblTemp release]; 

    //Initialize Label with tag 6. 
    lblTemp = [[UILabel alloc] initWithFrame:LabelCmpnyName2Frame]; 
    lblTemp.tag = 4; 
    //lblTemp.font = [UIFont fontNamesForFamilyName:@"Arial"]; 
    lblTemp.font = [UIFont fontWithName:@"Arial-BoldMT" size:13]; 
    lblTemp.backgroundColor = [UIColor clearColor]; 
    [cell.contentView addSubview:lblTemp]; 
    [lblTemp release]; 

    return cell; 
} 
0

あなたのテーブルビューの行は、私はこれがとにかく行うための最善のことであるかどうか分かりませんが、あなたは単に、サブビューとしていくつかのラベルを追加することができ、図です。

あなたは何を達成しようとしていますか? 4のラベルは、iPhoneが持っている小さな画面ではちょっと見えます。

2

UITableViewCellオブジェクトがcontentView性質を持っています。任意のカスタムビューをサブビューとしてcontentViewとして追加します。何をしたい

1

あなたがUITableViewCellで簡単にこのことを行うことができます。 1つのカスタムセルを作成して、必要な数のラベルを追加します。そのカスタムセルをテーブルビューに追加します。 follwoingコードを参照してください:

@interface EditingTableCell : UITableViewCell 
{ 
    UILabel  *status; 
    UILabel  *valueofplayername; 
} 

@property (nonatomic,retain) IBOutlet UILabel *status; 
@property (nonatomic,retain) IBOutlet UILabel *valueofplayername; 

はIBから1 uitableviewcellを取り、あなたのIBOutletであなたのラベルやリンクを追加します。この 後、あなたのcellForRowAtIndexPathデリゲートにこのコードを追加します。

EditingTableCell *cell = (EditingTableCell *)[tableView dequeueReusableCellWithIdentifier:IngredientsCellIdentifier]; 
if (cell == nil) 
{ 
    [[NSBundle mainBundle] loadNibNamed:@"EditingTableCell" owner:self options:nil]; 
    cell = edittableviewcell; 
    self.edittableviewcell = nil; 
} 

チェックこのリンク: "?私はできHAZ TEH codez" これはQ&Aサイト、ではありませんhttp://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/