【问题标题】:Jailbreak Tweak Learning - UIViewController (separate file) with initWithFrame - code provided越狱调整学习 - 带有 initWithFrame 的 UIViewController(单独文件) - 提供的代码
【发布时间】:2015-02-24 23:14:30
【问题描述】:

我正在学习如何创建越狱调整。

我希望这只是一个简单的问题。我正在使用 Theos。

我有以下设置:-

OneView.h

#import <UIKit/UIKit.h>

@interface OneView : UIViewController

@end

======================================

OneView.m

#import "OneView.h"

@interface OneView ()

@end

@implementation OneView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setOpaque:NO];
    }
    return self;
}

@end

======================================

调整.xm

#import <UIKit/UIKit.h>
#include "OneView.h"

//这个功能可以正常编译

%new
-(void)createView:() {
        UIView *view11 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 272)];  
        view11.backgroundColor = [UIColor redColor];  
        [self.view addSubview:view11];
}
%end

//这不起作用它会在我编译时产生错误。

%new 
-(void)createOneView:() {
        OneView *view11 = [[OneView alloc] initWithFrame:CGRectMake(0, 0, 480, 272)];  
        view11.backgroundColor = [UIColor redColor];  
        [self.view addSubview:view11];
}
%end

======================================

错误

 Preprocessing Tweak.xm...
 Compiling Tweak.xm...
Tweak.xm:144:44: error: 

'OneView' may not respond to 'initWithFrame:' [-Werror]

        OneView *view11 = [[OneView alloc] initWithFrame:CGRectMake(0, 0, 480, 
272)];  
                           ~~~~~~~~~~~~~~~ ^
Tweak.xm:145:16: error: property 'backgroundColor' not found on object of type 'OneView *'
        view11.backgroundColor = [UIColor redColor];  
               ^
Tweak.xm:146:31: error: cannot initialize a parameter of type 'UIView *' with an lvalue of type 'OneView *'
        [self.view addSubview:view11];

It does not like initWithFrame! is this something to do with headers !

谢谢

===========================

Error when inheriting UIView

bash-3.2# make package
Making all for tweak OneView...
 Preprocessing Tweak.xm...
 Compiling Tweak.xm...
 Linking tweak OneCall...
Undefined symbols for architecture armv7:
  "_OBJC_CLASS_$_OneCallView", referenced from:
      objc-class-ref in Tweak.xm.249b7f24.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [obj/OneView.dylib.ba964c90.unsigned] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [OneView.all.tweak.variables] Error 2

=========================

继承 UIViewController 时出错(更新)

        OneView *view11 = [[OneView alloc] initWithFrame:CGRectMake(0, 0, 480, 272)];  
        view11.view.backgroundColor = [UIColor redColor];  
        [self.view addSubview:view11];

'OneView' 可能不响应'initWithFrame:' [-Werror]

        OneView *view11 = [[OneView alloc] initWithFrame:CGRectMake(0, 0, 480, 
272)];  

【问题讨论】:

    标签: ios objective-c jailbreak theos cydia-substrate


    【解决方案1】:

    您将 OneView 设为 UIViewController 的子类:

    @interface OneView : UIViewController
    

    但你必须让它成为 UIView 的子类:

    @interface OneView : UIView
    

    【讨论】:

    • 你好,这不是问题,你继承 UIViewController 还是 UiView 都是一样的错误。
    • 这绝对是问题所在。 UIViewController 没有名为 initWithFrame:frame 的初始化函数,如错误日志中所示。此函数由 UIView 或从它继承的任何类使用。正如您的错误日志也显示的那样,UIViewController 没有名为 backgroundColor 的属性。它是 UIView 的一个属性。我建议再次检查您的代码
    • 嗨,对不起,我在之前的评论中没有正确解释自己,所以我很抱歉我也是色盲,没有看到背景颜色属性,但它只是因为我在剪切和粘贴,但是我试图让它与 UIViewController 一起工作,而不仅仅是 UIView。如果 OneView 继承 UIView,我仍然会收到错误消息。我在底部更新了上面的错误,请看一下。感谢您的帮助并耐心等待我,这样我才能得到这个:)
    • 嗨马,我接受了你的回答,因为我在我的问题中犯了一个错误,我遇到的问题是当我继承 UIView 时它没有正确链接,如你在上面的底部看到的那样。我发现我忘记在 make 文件中包含 OneView.m(我知道真的很傻)但还是谢谢你。
    【解决方案2】:

    createOneView 是保留的方法名称,不能重新定义。只需将它的名称更改为对您作为程序员仍然有意义的其他名称,它应该没问题!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      • 2023-04-02
      • 1970-01-01
      • 2014-04-25
      • 2020-08-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多