开发者

Public IBOutlet

开发者 https://www.devze.com 2023-02-21 01:17 出处:网络
I want to use an IBOutlet from classA on classB Why is this not working? ClassA.h @interface ClassA : UIViewController {

I want to use an IBOutlet from classA on classB

Why is this not working?

ClassA.h

@interface ClassA : UIViewController {
           @public IBOutlet UILabel* myLabel;
           }
@property (nonatomic, retain) UILabel* myLabel;
@end

ClassB.m

#import "ClassA.h"
#import "ClassB.h" 
@implementation ClassB
           ClassA.myLabel.text =  @"Any String";

Xcode sends this error: internal compiler error: Segmentation fault

Or, is there another way to do this? This problem is killing me!

T开发者_JAVA技巧hanks in advance


Did you copy&paste this directly from XCode? Your code looks strange.
- ClassB.m should not contain the implementation of ClassA (this should go to ClassA.m)
- You probably don't want ClassA.myLabel.text, but instance_of_ClassA.myLabel.text

If this doesn't help, could you please provide some more information?


Hmmm, that code looks like it was written by a C++ coder. Don't cross the streams. This is an ancient questions but I couldnt resist fixing such a basic error.

ClassA.h

@interface ClassA : UIViewController {}
@property (nonatomic, retain) IBOutlet UILabel* myLabel; // iVar is created for you by compiler
@end

ClassB.m

#import "ClassA.h"
#import "ClassB.h" 
@implementation ClassB
  -(void)youNeedToBeInsideAMethod {
    classAInstance.myLabel.text =  @"Genius!";
  }
@end

ObjectiveC != C++ or vice versa (of course there is always Objective C++)

0

精彩评论

暂无评论...
验证码 换一张
取 消