归因于TableView Cell上的文本无效

use*_*876 4 iphone objective-c ios ios7 textkit

尝试在TabelViewCell上使用不同的字体和字体大小,但它不起作用.

这是我尝试过的:

cell.textLabel.attributedText = [infoCells objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

此代码使应用程序崩溃

然后我尝试了这个:

cell.textLabel.text = [infoCells objectAtIndex:indexPath.row];
Run Code Online (Sandbox Code Playgroud)

现在一切正常但字体和字体大小不会改变.

以下是我的应用中的一些代码:

- (void)viewDidLoad
{
    [super viewDidLoad];

    infoCells  = [[NSMutableArray alloc] initWithCapacity:2];


    [infoCells addObject:@"DOI"];
    [infoCells addObject:@"WIS?"];
    [infoCells addObject:@"?????????? ?????? ????????????? ?????????? ???????????????? ????????????"];

}

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


    // Configure the cell...

    cell.textLabel.attributedText = [infoCells objectAtIndex:indexPath.row];

    cell.textLabel.font = [UIFont fontWithName:@"Adobe Arabic" size:20];

    return cell;  

}
Run Code Online (Sandbox Code Playgroud)

Dha*_*ngh 7

您需要创建一个NSMutableAttributedString字符串然后分配它.因此,有关详细信息,请参阅此示例.

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


        // Configure the cell...

    NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:[infoCells objectAtIndex:indexPath.row]];
 [str addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Helvetica-Bold" size:50] range:NSMakeRange(0, str.length)];

        cell.textLabel.attributedText = str;

        //cell.textLabel.font = [UIFont fontWithName:@"Adobe Arabic" size:20];

        return cell;  

    }
Run Code Online (Sandbox Code Playgroud)