UIBarButtonItem, ссылающийся на пользовательское представление для последующего редактирования - PullRequest
1 голос
/ 23 сентября 2011

Надеюсь, это простой вопрос, у меня есть UIBarButtonItem, который я инициализировал, используя UILabel в качестве пользовательского представления, кнопка находится внутри панели инструментов. То, что я хочу сделать, это возможность изменить текст с метки, которая находится внутри UIBarButtonItem, вот мой код:

    NSDate *lastUpdateDate = [AWSyncEntity getLastUpdatedDateByEntityName:@"Patient" inManagedObjectContext:self.managedObjectContext]; 

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];//liberar
    [dateFormat setDateFormat:@"MM/dd/yyyy hh:mm a"];

    UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 44.01)]; //liberar
    myLabel.font = [UIFont boldSystemFontOfSize:10];
    myLabel.textColor = [UIColor whiteColor];
    myLabel.backgroundColor = [UIColor clearColor];
    myLabel.text = [NSString stringWithFormat:@"Actualizado: %@", [dateFormat stringFromDate:lastUpdateDate]];

    UIBarButtonItem *btn2 = [[UIBarButtonItem alloc] initWithCustomView:myLabel]; //liberar    
    UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; //liberar        
    self.toolbarItems = [NSArray arrayWithObjects:flexibleSpace,btn2, flexibleSpace, nil];
    [self.navigationController setToolbarHidden:NO animated:YES];

    UIBarButtonItem *mybtn = (UIBarButtonItem *)[self.toolbarItems objectAtIndex:2];    
    //I was thinking this would be possible...
    //UILabel *mylbl = (UILabel *) [mybtn view];

    [flexibleSpace release];
    [btn2 release];
    [myLabel release];
    [dateFormat release];

Понятия не имею, как снова получить ссылку на внутренний вид кнопки, какие-нибудь подсказки? Я думал о том, чтобы сделать что-то вроде этого: (но это не работает).

    //I was thinking this would be possible...
    //UILabel *mylbl = (UILabel *) [mybtn view];

Ответы [ 2 ]

0 голосов
/ 23 сентября 2011

UILabel * myLbl = (UILabel *) [mybtn customView];

это должно сделать, но я не проверял это.

0 голосов
/ 23 сентября 2011

Метка - это customView кнопки панели,

UILabel *mylbl = (UILabel *)[mybtn customView];
...