2011-01-12 6 views
2

UITableViewCellのフォントサイズを小さくしようとしています。ここで私が持っているコードです:UITableViewCellフォントサイズが変更されていません

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString* CellIdentifier = @"Cell"; 
    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier]; 

    UILabel *nameLabel; 
    UISwitch *mySwitch; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault 
             reuseIdentifier: CellIdentifier] autorelease]; 

     nameLabel = [[[UILabel alloc] initWithFrame:CGRectMake(220, 13, 100, 20)] autorelease]; 
     nameLabel.tag = 22; 
     nameLabel.font = [UIFont boldSystemFontOfSize: 5.0]; 
     nameLabel.textColor = [UIColor blueColor]; 
     nameLabel.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleHeight; 
     nameLabel.backgroundColor = [UIColor clearColor]; 
     [cell.contentView addSubview: nameLabel]; 

     mySwitch = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease]; 
     mySwitch.tag = ((400*(indexPath.section+1))+indexPath.row); 
     [mySwitch addTarget:self action:@selector(switchChanged:) forControlEvents:UIControlEventValueChanged]; 
     [cell addSubview:mySwitch]; 
     cell.accessoryView = mySwitch; 


    } 
    else { 
     nameLabel = (UILabel*)[cell.contentView viewWithTag: 22]; 
     mySwitch = (UISwitch *)[cell.contentView viewWithTag:((400*(indexPath.section+1))+indexPath.row)]; 
    } 

    nameLabel.textLabel.text = @"Hello"; 


} 

は、しかし、ラベルのフォントは、確かにそれはおそらく、フォントサイズ12、または任意デフォルトはについては、通常のフォントと通常のサイズですサイズ5であることをカミングアウトされていません。フォントサイズを変更できないのはなぜですか?

+0

あなたが二回セルのcontentViewにnameLabelを追加しているが理由でしょうか? –

+0

タイプミス、申し訳ありません。私はそれらの1つを削除しました。それでも同じ問題があります。 – CodeGuy

答えて

0

は、代わりにnameLabel.textLabel.text = @"Hello";

使用して問題とは無関係の

nameLabel.text = @"Hello"; 
2

のこの

を試してみてください、しかし、サブビューとしてスイッチを追加する必要はありません。アクセサリビューを設定すると、アクセサリビューをセルに追加して保持する必要があります。

[cell addSubview:mySwitch]; 
    cell.accessoryView = mySwitch; 

...ちょうどでなければなりません...

[cell setAccessoryView:mySwitch]; 
関連する問題