Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIBarButtonim引用自定义视图以供以后编辑_Iphone_Uiview_Uibarbuttonitem_Objective C++ - Fatal编程技术网

Iphone UIBarButtonim引用自定义视图以供以后编辑

Iphone UIBarButtonim引用自定义视图以供以后编辑,iphone,uiview,uibarbuttonitem,objective-c++,Iphone,Uiview,Uibarbuttonitem,Objective C++,我希望这是一个简单的问题,我有一个UIBarButtonim,我使用UILabel作为自定义视图初始化它,按钮位于工具栏内。 我想做的是能够更改UIBarButtonItem内标签的文本,以下是我的代码: NSDate *lastUpdateDate = [AWSyncEntity getLastUpdatedDateByEntityName:@"Patient" inManagedObjectContext:self.managedObjectContext]; NSDat

我希望这是一个简单的问题,我有一个UIBarButtonim,我使用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];
我不知道如何再次参考按钮的内部视图,有什么线索吗? 我正在考虑做这样的事情:(但它不起作用)

标签是工具栏按钮的自定义视图

UILabel *mylbl = (UILabel *)[mybtn customView];
UILabel*myLbl=(UILabel*)[mybtn自定义视图]


这应该可以,但我还没有测试它。

谢谢,我知道它很简单,但我没能找到它,谢谢,尽管它没有按我预期的方式工作。我想引用标签的原因是为了更新其内容,我希望在工具栏中显示一个时间戳,并对其进行多次更新,但按照我最初发布的方式进行操作并不会刷新标签文本,我唯一能想到的其他方法是创建一个新按钮,并使用新的时间戳再次将其分配给工具栏,你能想出更好的方法吗?对不起,想不出更好的方法(我自己也是初学者,只编写了几个月的代码),但如果我有帮助,请单击绿色复选标记接受我的答案!
UILabel *mylbl = (UILabel *)[mybtn customView];