小编six*_*way的帖子

如何在以编程方式创建的UILabel上添加padding-left?

我知道这是一个菜鸟问题,但是...我在桌面视图上有这些标签,但文字完全被压到了左边.我想添加一些填充.我该怎么办呢?

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  {

    UIView* customView = [[[UIView alloc] initWithFrame:CGRectMake(10,0,300,60)] autorelease];

    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];

    headerLabel.backgroundColor = [UIColor colorWithHexString:[[_months objectAtIndex:section] objectForKey:@"color"]];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.frame = CGRectMake(0,0,400,30);
    headerLabel.text =  [[_months objectAtIndex:section] objectForKey:@"name"];

    headerLabel.textColor = [UIColor whiteColor];


    [customView addSubview:headerLabel];

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

任何帮助深表感谢!谢谢!

iphone objective-c ios

21
推荐指数
4
解决办法
7万
查看次数

核心数据:索引x处的获取对象具有乱序部分名称'xxxxxx.对象必须按节名称排序

我知道我不是第一个提出这个问题的人,但我真的很难过......

基本上我有一个带两个按钮的屏幕.每个按钮根据日期将数据加载到下面的桌面视图中.在第一个tableview的第一次加载时(默认选中左键),一切正常.如果我点击右键,我得到一个空白的tableview,我得到错误

索引x处的获取对象具有无序部分名称'xxxxxx.对象必须按节名称排序.

切换回左表视图,数据消失了.两个tableviews都是空的.

每个tableview有2个部分,具体取决于项目的开始时间.如果我删除部分数据显示正常.不幸的是我需要它们..数据分为两部分,如下所示:

@interface NSString(agendaSessionKeyPath)
@property (nonatomic, readonly) NSString *sessionSection;
@end

@implementation NSString(agendaSessionKeyPath)

- (NSString *)sessionSection
{
    int timeValue = [[self stringByReplacingOccurrencesOfString:@":" withString:@""] intValue]; //turns 11:00 to 1100
    if (timeValue < 1200)
        return @"Morning";
     else
        return @"Afternoon";
}
Run Code Online (Sandbox Code Playgroud)

获取请求

- (void)viewDidLoad
{
     //other viewDidLoad stuff
    [self fetchSessions];
}
Run Code Online (Sandbox Code Playgroud)

根据日期从左右按钮对数据进行排序的方法:

- (void)fetchSessions
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];

    NSDate* date = nil;
    if (selected == 0) //left button is selected
    {
        date = …
Run Code Online (Sandbox Code Playgroud)

iphone core-data objective-c nsfetchedresultscontroller ios

21
推荐指数
1
解决办法
8361
查看次数

AFNetworking:setImageWithURLRequest没有设置图像

我正在尝试在tableViewCell 上ImageView使用AFNetworking 设置图像setImageWithURLRequest.如果我不在方法中包含successfailure块,如下所示:

[cell.thumbnailImageView setImageWithURL:url placeholderImage:nil]; 
Run Code Online (Sandbox Code Playgroud)

一切都很完美,图像设置.不幸的是我需要块.

这是我目前所拥有的cellForRowAtIndexPath:

if (self.images) { //check if the array of images is set, fetched from a URL

        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: [[self.images objectAtIndex:indexPath.row] objectForKey:@"tbUrl"]]];

        [cell.thumbnailImageView setImageWithURLRequest:request placeholderImage:[UIImage imageNamed:@"placeholder"] success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
                NSLog(@"success"); //it always lands here! But nothing happens
        } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) {
                NSLog(@"fail");
        }];

    }
Run Code Online (Sandbox Code Playgroud)

iphone block ios afnetworking

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

通过计时器更新UILabel无法正常工作

我正在尝试更新从用户生日到晚些时候倒计时的UILabel.我正在尝试更新标签,以便他们可以看到它倒计时但似乎无法使其正常工作.建议表示赞赏!

这是我制作计时器的地方:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeFormatted:) userInfo:nil repeats:NO];
}
Run Code Online (Sandbox Code Playgroud)

这里是我获得实际倒计时信息的地方......

- (NSString *)timeFormatted:(int)totalSeconds
{       
    NSTimeInterval theTimeInterval = [self numberOfSecondsToLive];

    NSCalendar *sysCalendar = [NSCalendar currentCalendar];

    NSDate *date1 = [[NSDate alloc] init];
    NSDate *date2 = [[NSDate alloc] initWithTimeInterval:theTimeInterval sinceDate:date1]; 

    unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSSecondCalendarUnit;

    NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1  toDate:date2  options:0];

  _numberofSeconds.text = [NSString …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

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