2012-01-12 98 views
0

进出口访问标签在一个或者Controller.h从IOS其他控制器

@interface ColorPickerViewController : UIViewController { 

    IBOutlet UILabel *Labelniz; 
} 

    @property (nonatomic, retain) UILabel* Labelniz; 

此代码尝试这种代码在Controller.m或者

@implementation ColorPickerViewController 

@synthesize Labelniz=_Labelniz; 

但使用我像ColorPickerViewController.Labelniz给出了一个错误。 预先感谢您。

回答

1

在UIViewController中创建要访问标签的属性,就像使用ColorPickerViewController中的标签一样。然后,当你推动/呈现新视图时,将其设置为自己。

ColorPickerViewController *colorPickerViewController; 
@propery (nonatomic, retain) ColorPickerViewController *colorPickerViewController; 

,当然还有:

@syntesize colorPickerViewController 

它设置为自己的观点,提出正确的之前:

viewThatYouArePresenting.colorPickerViewController = self. 
[self.navigationController pushViewController:youViewController animated:YES]//Or whichever your using, this is just an example 

,那么你可以从视图设置它就像你正在做的:

colorPickerViewController.Labelniz = @"xxxxx"; 

这样做:

ColorPickerViewController *controller = [[ColorPickerViewController alloc] init]; 

实例化控制器的另一个实例,因此基本上变化的新instatiated标签ColorPickerViewController.What你想要的是改变标签在已经实例化的ColorPickerViewController。

+0

谢谢,很好的回答! – 2012-01-13 19:42:18

0

我希望你做这种方式

ColorPickerViewController *controller = [[ColorPickerViewController alloc] init]; 

controller.Labelniz = ....... 

ColorPickerViewController是类和控制器是对象。您可以访问特定对象的属性(在本例中为控制器对象的Labelniz属性)。

+0

它没有提供任何错误,但它不适用于我 - 它不会更改标签的文本。 – 2012-01-12 18:26:22

+0

你试过controller.Labelniz.text = @“whatEverText”; ? 如果您正在开始学习iOS开发,请查看developer.apple.com的示例代码将更有帮助 – 2012-01-12 21:58:51

+0

是的,我已经尝试过这一切。 – 2012-01-13 19:41:57