Objective c 如何在Xcode中从一个类访问或操作另一个类的变量
我是IOS编程的新手,因此有点难以解决以下问题。我会尽我所能描述这个问题,非常感谢您的帮助Objective c 如何在Xcode中从一个类访问或操作另一个类的变量,objective-c,ios,Objective C,Ios,我是IOS编程的新手,因此有点难以解决以下问题。我会尽我所能描述这个问题,非常感谢您的帮助 - (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { TestView *t = [[TestView alloc]init]; if (toInterfaceOrientation
- (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
TestView *t = [[TestView alloc]init];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
[t.imgIcon setFrame:CGRectMake(10,74,165,190)];
[t.lbltitle setFrame:CGRectMake(20, 10, 387, 21)];
}
else
{
[t.imgIcon setFrame:CGRectMake(10,74,165,190)];
[t.lbltitle setFrame:CGRectMake(189, 10, 387, 21)];
}
}
我创建了以下内容:
- AboutViewController(.h、.m和.xib),它有两个子视图,称为-mainView、infoView。mainView和infoView接口是在XIB文件中创建的
- TestView(处理初始化的视图,在mainView和infoView之间切换)
@interface TestView : UIView {
IBOutlet UIView *mainView;
IBOutlet UIView *infoView;
UILabel *lbltitle;
UIImageView *imgIcon;
IBOutlet UITextView *txtInfo1;
IBOutlet UITextView *txtInfo2;
IBOutlet UITextView *txtInfo3;
}
@property (nonatomic, retain) IBOutlet UILabel *lbltitle;
@property (nonatomic, retain) IBOutlet UIImageView *imgIcon;
#import "TestView.h"
#import <QuartzCore/QuartzCore.h>
@implementation TestView
@synthesize lbltitle, imgIcon;
-(void)awakeFromNib
{
[self addSubview:mainView];
}
TestView.m如下所示:
@interface TestView : UIView {
IBOutlet UIView *mainView;
IBOutlet UIView *infoView;
UILabel *lbltitle;
UIImageView *imgIcon;
IBOutlet UITextView *txtInfo1;
IBOutlet UITextView *txtInfo2;
IBOutlet UITextView *txtInfo3;
}
@property (nonatomic, retain) IBOutlet UILabel *lbltitle;
@property (nonatomic, retain) IBOutlet UIImageView *imgIcon;
#import "TestView.h"
#import <QuartzCore/QuartzCore.h>
@implementation TestView
@synthesize lbltitle, imgIcon;
-(void)awakeFromNib
{
[self addSubview:mainView];
}
特别的问题是你操作了一个你刚刚用
TestView *t = [[TestView alloc]init];
您不会在任何地方显示视图,因此它位于内存中。您可以应用所需的所有更改,但要查看这些更改,必须首先显示视图:
找到合适的家长并执行以下操作:
[parentview addSubview:t];
一般来说,您不应该在旋转处理代码中创建新视图。ok;以下是我正在努力实现的目标,请指导我怎样做才是最好的方法。我有一个选项卡视图,每个选项卡都有自己的xib文件。在其中一个选项卡上,我想显示一系列图片,单击该图片后,我想将视图切换到另一个选项卡,其中包含有关所单击图片的更多详细信息。这里是指确切的位置?我太快点击了“返回”;我已经编辑了评论-你能再看一眼吗?这听起来是一个使用UITableView的完美地方。或者,如果您的照片很少,只需创建一个滚动视图,用按钮填充它,将您的图像作为前景。