小编Shi*_*eng的帖子

UITableViewCell字体不变

我试图在UITableViewCell填充tableview时使用以下代码自定义a的字体.

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

    static NSString *MyIdentifier = @"MyIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if (cell == nil) 
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
    }

    // Set up the cell  
    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];   
    NSString *temp = [[NSString alloc] initWithString:[[stories objectAtIndex: storyIndex] objectForKey: @"title"]];
    cell.textLabel.text = temp;
    [[cell textLabel] setTextColor:[UIColor colorWithRed:154.0/255.0 green:14.0/255.0 blue:2.0/255.0 alpha:1]];
    [[cell textLabel] setFont:[UIFont systemFontOfSize:12.0]];  

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

对于我的生活,我不知道为什么它不会改变字体!如果我在单元格文本中进行硬编码,上面的代码也能正常工作cell.textLabel.text = @"TEST";

有什么建议?谢谢!

iphone uitableview

16
推荐指数
2
解决办法
2万
查看次数

@property实际上在幕后做了什么......使用自我.和自我 - >和_下划线

我仍然在努力解决@implementation部分中的语法错误.

所以,我想了解使用@property与否之间的区别.

第一种情况是一个@interface,我在{}中声明了一些变量.

//ViewController.h


#import <UIKit/UIKit.h>
#import "Student.h"       // just class i made

@interface ViewController : UIViewController
{
    Student *stObj;
}
Run Code Online (Sandbox Code Playgroud)

而且,我正在尝试使用几个标识符(_(下划线),self.,self->,没有)引用stObj指针

//  ViewController.m


#import "ViewController.h"

@interface ViewController () // just leaving this code cuz i haven't study what it is :)

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    stObj = [[Student alloc]init ];        //no error

    //self->stObj = [[Student alloc]init];  //no error
    //self.stObj = [[Student alloc]init];   //error!
    //_stObj = [[Student alloc]init];       //error!



 }
Run Code Online (Sandbox Code Playgroud)

第二种情况是@interface,我使用@property

@interface ViewController : …
Run Code Online (Sandbox Code Playgroud)

properties objective-c ios

2
推荐指数
1
解决办法
253
查看次数

标签 统计

ios ×1

iphone ×1

objective-c ×1

properties ×1

uitableview ×1