小编dcr*_*tar的帖子

如何在没有XIB文件的情况下以编程方式更新Xcode中的UILabel?

我被卡住了:(
在我的应用程序中,每当它获得新位置的更新时我都需要从CLLocationManager更新.我没有使用XIB/NIB文件,我编写的所有内容都是以编程方式完成的.代码:
.h


@interface TestViewController : UIViewController
    UILabel* theLabel;

@property (nonatomic, copy) UILabel* theLabel;

@end
Run Code Online (Sandbox Code Playgroud)

.m


...

-(void)loadView{
    ....
    UILabel* theLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)];
    theLabel.text = @"this is some text";

    [self.view addSubView:theLabel];
    [theLabel release]; // even if this gets moved to the dealloc method, it changes nothing...
}

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    NSLog(@"Location: %@", [newLocation description]);

    // THIS DOES NOTHING TO CHANGE TEXT FOR ME... HELP??
    [self.view.theLabel setText:[NSString stringWithFormat: @"Your Location is: %@", [newLocation description]]]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode uilabel settext ios

9
推荐指数
1
解决办法
4万
查看次数

标签 统计

ios ×1

iphone ×1

settext ×1

uilabel ×1

xcode ×1