gpt4 book ai didi

iphone - ios - 如何在现有类(class)中分配新类(class)?

转载 作者:行者123 更新时间:2023-11-29 03:52:13 27 4
gpt4 key购买 nike

我是 iPhone 开发新手,我想在现有类中分配一个类

这就是 C# 中的声明

public partial class UserRegisteration : System.Web.UI.Page
{
//some methods

public class Mime
{
//some methods
}
}

像 Objective-C 中的上述格式一样,如何在现有类中再分配一个类?

有什么想法吗?提前致谢。

最佳答案

是的,可以。我正在使用现有类中的一个类。一种是扩展 UIView,另一种是扩展 NSObject

MultiLayout.h

    @interface MultiLayout  : UIView
{
// methods and properties
}

@end

@interface SingleControl : NSObject
{
// methods and properties
}

@end

MultiLayout.m

@implementation SingleControl

//methods and variables declaration and property synthesization

@end

@implementation MultiLayout

//methods and variables declaration and property synthesization

@end

用于获取 MultiLayout 中 SingleControl 的静态值。你必须调用类方法,例如:

MultiLayout.h

 @interface  MultiLayout : UIView
{
// methods and properties
}

@end

@interface SingleControl : NSObject
{
// methods and properties
}

// add class method
+(int)getValue;

@end

MultiLayout.m

    @implementation SingleControl

// add static value
static int values = 100;


// implement method

+(int)getValue{
return values;
}

@end

@implementation MultiLayout

// call method to get value

[SingleChoiceControl getValue];

@end

关于iphone - ios - 如何在现有类(class)中分配新类(class)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16958599/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com