2014-10-20 15 views
7

Người dùng của chúng tôi đang gặp sự cố định kỳ theo phương pháp bên dưới. Các sự cố xảy ra luôn ở một trong các dòng: [lbl sizeToFit] (biến số lbl được khởi tạo lại và sử dụng lại. Theo hiểu biết của tôi, điều này sẽ không gây ra bất kỳ vấn đề nào).IOS8 - [Kích thước nhãn UIToFit] gây ra lỗi EXC_BAD_ACCESS KERN_INVALID_ADDRESS

Các sự cố này chỉ xảy ra trên iOS8 (cùng một phương pháp đã được sử dụng trong một thời gian rất dài trên ios7 mà không có bất kỳ vấn đề nào). Tôi không thể tái tạo tai nạn này. Hiện nay, chì duy nhất của tôi là từ tài liệu táo 'sizeToFit':

..In một số trường hợp, nếu một cái nhìn không có một SuperView, nó có thể kích thước riêng của mình để giới hạn màn hình. Do đó, nếu bạn muốn một khung nhìn cụ thể tự kích thước cho khung nhìn cha mẹ của nó, bạn nên thêm nó vào khung nhìn cha mẹ trước khi gọi phương thức này.

Tuy nhiên, tôi không thấy làm thế nào điều này có thể tạo ra sự cố bộ nhớ kém.

-(void)setUpHeaders:(NSInteger)fortype{ 
    headers = [NSMutableArray array]; 
    if(fortype == GROUP_BY_TIME){ 

    for(int i=0;i<4;i++){ 
     UIView* header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 68)]; 
     header.backgroundColor = [UIColor whiteColor]; 
     [headers addObject:header]; 
    } 

    int today = (int)[NSDate dayOfTheWeekOfDate:[NSDate date]]; 
    int firstDayOfTheWeek = (int)[defaults integerForKey:FIRST_DAY_IF_THE_WEEK_KEY]; 
    NSString* restOfTheWeek = nil; 
    if(today == ((firstDayOfTheWeek + 4) % 7) + 1) restOfTheWeek = MyLocalizedString(@"THE COMING WEEK", @"THE COMING WEEK") ; 
    else if(today == ((firstDayOfTheWeek + 5) % 7) + 1) restOfTheWeek = MyLocalizedString(@"REST OF NEXT WEEK", @"REST OF NEXT WEEK") ; 
    else restOfTheWeek = MyLocalizedString(@"REST OF THE WEEK", @"REST OF THE WEEK") ; 

    UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 22; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"TODAY", @"TODAY") ]; 
    [lbl sizeToFit]; 
    [[headers objectAtIndex:0] addSubview:lbl]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake([MyLocalizedString(@"TODAY", @"TODAY") sizeWithFont:[UIFont fontWithName:@"Volkswagen-Serial-Medium-Regular" size:21]].width + 15, 41, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = [UIFont fontWithName:@"Volkswagen-Regular" size:19]; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]]; 
    [lbl setText:[NSString stringWithFormat:@" %@, %@ %d ",[[[NSLocale currentLocale] localeIdentifier] containSubString:@"he"] ? [[[NSDate date] dayOfTheWeekString] uppercaseString] : [[[NSDate date] threeLetterDayOfTheWeekString] uppercaseString],[NSDate abbriviatedMonthForDate:[NSDate date]],(int)[components day]]]; 
    lbl.textAlignment = NSTextAlignmentCenter; 
    [lbl sizeToFit]; 
    [[headers objectAtIndex:0] addSubview:lbl]; 

    UIImageView *img; 
    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:0] addSubview:img]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.origin.x+2, 40, 1, 19)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 33; 
    [[headers objectAtIndex:0] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 22; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"TOMORROW", @"TOMORROW")]; 
    [lbl sizeToFit]; 
    [[headers objectAtIndex:1] addSubview:lbl]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake([MyLocalizedString(@"TOMORROW", @"TOMORROW") sizeWithFont:[UIFont fontWithName:@"Volkswagen-Serial-Medium-Regular" size:21]].width + 15, 41, 200, 30)]; 
    lbl.tag = 2; 
    lbl.font = [UIFont fontWithName:@"Volkswagen-Regular" size:19]; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate dateWithTimeIntervalSinceNow:86400]]; 
    [lbl setText:[NSString stringWithFormat:@" %@, %@ %d ",[[[NSLocale currentLocale] localeIdentifier] containSubString:@"he"] ? [[[[NSDate date] dateByAddingDays:1] dayOfTheWeekString] uppercaseString] : [[[[NSDate date] dateByAddingDays:1] threeLetterDayOfTheWeekString] uppercaseString],[NSDate abbriviatedMonthForDate:[[NSDate date] dateByAddingDays:1]],(int)[components day]]]; 
    lbl.textAlignment = NSTextAlignmentCenter; 

    [lbl sizeToFit]; 
    [[headers objectAtIndex:1] addSubview:lbl]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:1] addSubview:img]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.origin.x+2, 40, 1, 19)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 33; 
    [[headers objectAtIndex:1] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:restOfTheWeek]; 
    [[headers objectAtIndex:2] addSubview:lbl]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:2] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"LATER", @"LATER")]; 
    [[headers objectAtIndex:3] addSubview:lbl]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:3] addSubview:img]; 

    lbl = (UILabel*)[[headers objectAtIndex:0] viewWithTag:2]; 
    todayWeather = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.size.width + lbl.frame.origin.x-5, 38, 30, 25)]; 
    [[headers objectAtIndex:0] addSubview:todayWeather]; 

    lbl = (UILabel*)[[headers objectAtIndex:1] viewWithTag:2]; 
    tomorrowWeather = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.size.width + lbl.frame.origin.x-5, 38, 30, 25)]; 
    [[headers objectAtIndex:1] addSubview:tomorrowWeather]; 

    [self gotWeather]; 

} 
else{ 
    NSMutableArray* labels = [[self getLabels] valueForKey:@"values"]; 

    CGRect headerFrame, labelFrame, seperatorFrame; 
    if ([defaults integerForKey:DISPLAY_TYPE]==DisplayTypeNotes) { 
     headerFrame = CGRectMake(0, 0, 320, 60); 
     labelFrame = CGRectMake(10, 30, 300, 30); 
     seperatorFrame = CGRectMake(0, 59, 320, 1); 
    }else{ 
     headerFrame = CGRectMake(0, 0, 320, 68); 
     labelFrame = CGRectMake(10, 38, 300, 30); 
     seperatorFrame = CGRectMake(0, 67, 320, 1); 

    } 


    for(int i=0;i<[labels count];i++){ 
     UIView* header = [[UIView alloc] initWithFrame:headerFrame]; 
     header.backgroundColor = [UIColor whiteColor]; 

     UILabel* lbl = [[UILabel alloc] initWithFrame:labelFrame]; 
     lbl.tag = 2; 
     lbl.font = XX_LARGE_VOLKS_FONT; 
     [lbl setBackgroundColor:[UIColor clearColor]]; 
     [lbl setTextColor:[UIColor darkGrayColor]]; 
     [lbl setText:[labels objectAtIndex:i]]; 
     [header addSubview:lbl]; 

     UIImageView *img; 
     img = [[UIImageView alloc] initWithFrame:seperatorFrame]; 
     [img setBackgroundColor:[UIColor darkGrayColor]]; 
     img.alpha = 0.5; 
     img.tag = 3; 
     [header addSubview:img]; 

     [header bringSubviewToFront:lbl]; 

     [headers addObject:header]; 
    } 
    //add aditonale header for unlabeled tasks\notes  
    UIView* header = [[UIView alloc] initWithFrame:headerFrame]; 
    header.backgroundColor = [UIColor whiteColor]; 

    UILabel* lbl = [[UILabel alloc] initWithFrame:labelFrame]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"Not Labeled", @"Not Labeled")]; 
    [header addSubview:lbl]; 

    UIImageView *img; 
    img = [[UIImageView alloc] initWithFrame:seperatorFrame]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [header addSubview:img]; 

    [headers insertObject:header atIndex:0]; 

    } 


} 

Thread : Crashed: com.apple.main-thread 
0 UIKit       0x000000018c4f22a0 -[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 640 
1 UIKit       0x000000018c4f228c -[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 620 
2 QuartzCore      0x000000018bb80198 CA::Layer::set_bounds(CA::Rect const&, bool) + 408 
3 QuartzCore      0x000000018bb7ff78 -[CALayer setBounds:] + 104 
4 UIKit       0x000000018c70fa50 -[_UILabelLayer setBounds:] + 56 
5 QuartzCore      0x000000018bb80c58 -[CALayer setFrame:] + 488 
6 UIKit       0x000000018c70f9e4 -[_UILabelLayer setFrame:] + 56 
7 UIKit       0x000000018c22de0c -[UIView(Geometry) setFrame:] + 292 
8 UIKit       0x000000018c23d69c -[UILabel setFrame:] + 140 
9 UIKit       0x000000018c23ea88 -[UIView(Geometry) sizeToFit] + 248 
10 24me       0x00000001001e292c -[ViewController setUpHeaders:] (ViewController.m:3412) 
11 24me       0x00000001001dfcac -[ViewController groupByTime] (ViewController.m:3146) 
12 24me       0x00000001001df6a0 -[ViewController group] (ViewController.m:3071) 
13 Foundation      0x0000000188970ea8 __NSFireDelayedPerform + 424 
14 CoreFoundation     0x0000000187a6a210 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 28 
15 CoreFoundation     0x0000000187a69ec0 __CFRunLoopDoTimer + 888 
16 CoreFoundation     0x0000000187a6790c __CFRunLoopRun + 1372 
17 CoreFoundation     0x0000000187995664 CFRunLoopRunSpecific + 396 
18 GraphicsServices    0x0000000190acf5a4 GSEventRunModal + 168 
19 UIKit       0x000000018c29a4f8 UIApplicationMain + 1488 
20 24me       0x00000001000642bc main (main.m:16) 
21 libdyld.dylib     0x000000019875ea08 start + 4 
+1

Got vấn đề tương tự với sizeToFit trong iOS8: EXC_BAD_ACCESS (mã = 2, địa chỉ = X52) – Misha

+0

Kể tìm bất cứ thứ gì về vấn đề này ? – Fatlad

+2

Bạn đã thử đảm bảo rằng nó đang chạy trên luồng chính? Tôi chắc chắn rằng tôi đã chạy vào một vấn đề tương tự gần đây nhưng không phải 100% vì vậy không muốn đăng bài như một câu trả lời. –

Trả lời

1

Tôi đã sửa đổi một chút mã của bạn và thêm nhận xét. Lưu ý phần được đánh dấu.

-(void)setUpHeaders:(NSInteger)fortype{ 
    headers = [NSMutableArray array]; 
    if(fortype == GROUP_BY_TIME){ 

    for(int i=0;i<4;i++){ 
     UIView* header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 68)]; 
     header.backgroundColor = [UIColor whiteColor]; 
     [headers addObject:header]; 
    } 

    int today = (int)[NSDate dayOfTheWeekOfDate:[NSDate date]]; 
    int firstDayOfTheWeek = (int)[defaults integerForKey:FIRST_DAY_IF_THE_WEEK_KEY]; 
    NSString* restOfTheWeek = nil; 
    if(today == ((firstDayOfTheWeek + 4) % 7) + 1) restOfTheWeek = MyLocalizedString(@"THE COMING WEEK", @"THE COMING WEEK") ; 
    else if(today == ((firstDayOfTheWeek + 5) % 7) + 1) restOfTheWeek = MyLocalizedString(@"REST OF NEXT WEEK", @"REST OF NEXT WEEK") ; 
    else restOfTheWeek = MyLocalizedString(@"REST OF THE WEEK", @"REST OF THE WEEK") ; 

    UILabel* lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 22; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"TODAY", @"TODAY") ]; 

[[header objectAtIndex: 0] addSubview: lbl]; // lưu ý phần này [lbl sizeToFit]; // luôn thêm nhằm mẹ của nó trước khi gọi 'sizeToFit' hoặc nó sẽ sụp đổ

lbl = [[UILabel alloc] initWithFrame:CGRectMake([MyLocalizedString(@"TODAY", @"TODAY") sizeWithFont:[UIFont fontWithName:@"Volkswagen-Serial-Medium-Regular" size:21]].width + 15, 41, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = [UIFont fontWithName:@"Volkswagen-Regular" size:19]; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate date]]; 
    [lbl setText:[NSString stringWithFormat:@" %@, %@ %d ",[[[NSLocale currentLocale] localeIdentifier] containSubString:@"he"] ? [[[NSDate date] dayOfTheWeekString] uppercaseString] : [[[NSDate date] threeLetterDayOfTheWeekString] uppercaseString],[NSDate abbriviatedMonthForDate:[NSDate date]],(int)[components day]]]; 
    lbl.textAlignment = NSTextAlignmentCenter; 

[[header objectAtIndex: 0] addSubview: lbl]; // lưu ý phần này [lbl sizeToFit]; // luôn thêm nhằm mẹ của nó trước khi gọi 'sizeToFit' hoặc nó sẽ sụp đổ

UIImageView *img; 
    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:0] addSubview:img]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.origin.x+2, 40, 1, 19)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 33; 
    [[headers objectAtIndex:0] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 22; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"TOMORROW", @"TOMORROW")]; 

[[header objectAtIndex: 1] addSubview: lbl]; // lưu ý phần này [lbl sizeToFit]; // luôn thêm nhằm mẹ của nó trước khi gọi 'sizeToFit' hoặc nó sẽ sụp đổ

lbl = [[UILabel alloc] initWithFrame:CGRectMake([MyLocalizedString(@"TOMORROW", @"TOMORROW") sizeWithFont:[UIFont fontWithName:@"Volkswagen-Serial-Medium-Regular" size:21]].width + 15, 41, 200, 30)]; 
    lbl.tag = 2; 
    lbl.font = [UIFont fontWithName:@"Volkswagen-Regular" size:19]; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:[NSDate dateWithTimeIntervalSinceNow:86400]]; 
    [lbl setText:[NSString stringWithFormat:@" %@, %@ %d ",[[[NSLocale currentLocale] localeIdentifier] containSubString:@"he"] ? [[[[NSDate date] dateByAddingDays:1] dayOfTheWeekString] uppercaseString] : [[[[NSDate date] dateByAddingDays:1] threeLetterDayOfTheWeekString] uppercaseString],[NSDate abbriviatedMonthForDate:[[NSDate date] dateByAddingDays:1]],(int)[components day]]]; 
    lbl.textAlignment = NSTextAlignmentCenter; 

[[header objectAtIndex: 1] addSubview: lbl]; // lưu ý phần này [lbl sizeToFit]; // luôn thêm nhằm mẹ của nó trước khi gọi 'sizeToFit' hoặc nó sẽ sụp đổ

img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:1] addSubview:img]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.origin.x+2, 40, 1, 19)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 33; 
    [[headers objectAtIndex:1] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:restOfTheWeek]; 

    [[headers objectAtIndex:2] addSubview:lbl]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:2] addSubview:img]; 

    lbl = [[UILabel alloc] initWithFrame:CGRectMake(10, 38, 300, 30)]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"LATER", @"LATER")]; 
    [[headers objectAtIndex:3] addSubview:lbl]; 

    img = [[UIImageView alloc] initWithFrame:CGRectMake(0, 67, 320, 1)]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [[headers objectAtIndex:3] addSubview:img]; 

    lbl = (UILabel*)[[headers objectAtIndex:0] viewWithTag:2]; 
    todayWeather = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.size.width + lbl.frame.origin.x-5, 38, 30, 25)]; 
    [[headers objectAtIndex:0] addSubview:todayWeather]; 

    lbl = (UILabel*)[[headers objectAtIndex:1] viewWithTag:2]; 
    tomorrowWeather = [[UIImageView alloc] initWithFrame:CGRectMake(lbl.frame.size.width + lbl.frame.origin.x-5, 38, 30, 25)]; 
    [[headers objectAtIndex:1] addSubview:tomorrowWeather]; 

    [self gotWeather]; 

} 
else{ 
    NSMutableArray* labels = [[self getLabels] valueForKey:@"values"]; 

    CGRect headerFrame, labelFrame, seperatorFrame; 
    if ([defaults integerForKey:DISPLAY_TYPE]==DisplayTypeNotes) { 
     headerFrame = CGRectMake(0, 0, 320, 60); 
     labelFrame = CGRectMake(10, 30, 300, 30); 
     seperatorFrame = CGRectMake(0, 59, 320, 1); 
    }else{ 
     headerFrame = CGRectMake(0, 0, 320, 68); 
     labelFrame = CGRectMake(10, 38, 300, 30); 
     seperatorFrame = CGRectMake(0, 67, 320, 1); 

    } 


    for(int i=0;i<[labels count];i++){ 
     UIView* header = [[UIView alloc] initWithFrame:headerFrame]; 
     header.backgroundColor = [UIColor whiteColor]; 

     UILabel* lbl = [[UILabel alloc] initWithFrame:labelFrame]; 
     lbl.tag = 2; 
     lbl.font = XX_LARGE_VOLKS_FONT; 
     [lbl setBackgroundColor:[UIColor clearColor]]; 
     [lbl setTextColor:[UIColor darkGrayColor]]; 
     [lbl setText:[labels objectAtIndex:i]]; 
     [header addSubview:lbl]; 

     UIImageView *img; 
     img = [[UIImageView alloc] initWithFrame:seperatorFrame]; 
     [img setBackgroundColor:[UIColor darkGrayColor]]; 
     img.alpha = 0.5; 
     img.tag = 3; 
     [header addSubview:img]; 

     [header bringSubviewToFront:lbl]; 

     [headers addObject:header]; 
    } 
    //add aditonale header for unlabeled tasks\notes  
    UIView* header = [[UIView alloc] initWithFrame:headerFrame]; 
    header.backgroundColor = [UIColor whiteColor]; 

    UILabel* lbl = [[UILabel alloc] initWithFrame:labelFrame]; 
    lbl.tag = 2; 
    lbl.font = XX_LARGE_VOLKS_FONT; 
    [lbl setBackgroundColor:[UIColor clearColor]]; 
    [lbl setTextColor:[UIColor darkGrayColor]]; 
    [lbl setText:MyLocalizedString(@"Not Labeled", @"Not Labeled")]; 
    [header addSubview:lbl]; 

    UIImageView *img; 
    img = [[UIImageView alloc] initWithFrame:seperatorFrame]; 
    [img setBackgroundColor:[UIColor darkGrayColor]]; 
    img.alpha = 0.5; 
    img.tag = 3; 
    [header addSubview:img]; 

    [headers insertObject:header atIndex:0]; 

    } 
} 
Các vấn đề liên quan