我在让海关细胞出现时遇到问题。下面我发布了我的代码的简化版本:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
NSLog(@"Being Called?");
//reuseID = @"newtableid";
self.backgroundColor = [UIColor redColor];
self.name = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 50)];
self.name.backgroundColor = [UIColor redColor];
[self addSubview:self.name];
return self;
}
Run Code Online (Sandbox Code Playgroud)
在我的 viewController 中,我在 ViewDidLoad 方法中设置了 tableView:
self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 400) style:UITableViewStylePlain];
self.table.delegate = self;
self.table.dataSource = self;
self.table.backgroundColor = [UIColor blackColor];
[self.view addSubview:self.table];
[self.table registerClass:NewTableViewCell.class forCellReuseIdentifier:@"Cell"];
Run Code Online (Sandbox Code Playgroud)
然后,我像这样完成 cellForRowAt 方法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个本机 swift 模块,其中包含一个可以在 javascript 代码中调用的函数。目前我有我的module.swift文件、我的module.m文件和桥接头。
这是 MyModule.swift:
import Foundation
@objc(MyModule)
class MyModule: NSObject {
@objc func callbackMethod(callback: RCTResponseSenderBlock) -> Void {
let resultsDict = [
"success" : true
];
callback([NSNull() ,resultsDict])
}
}
Run Code Online (Sandbox Code Playgroud)
这是 MyModule.m:
#import <Foundation/Foundation.h>
// CalendarManagerBridge.m
#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
@interface RCT_EXTERN_MODULE(MyModule, NSObject)
RCT_EXTERN_METHOD(callbackMethod:(RCTResponseSenderBlock)callback)
@end
Run Code Online (Sandbox Code Playgroud)
这是桥接标头:
#import React/RCTBridgeModule.h
#import React/RCTEventEmitter.h
Run Code Online (Sandbox Code Playgroud)
最后,这是我在 javascript 中的调用:
const { MyModule } = require('NativeModules');
MyModule.callbackMethod((err,r) => console.log(r));
Run Code Online (Sandbox Code Playgroud)
问题是,每当我运行该项目时,都会出现错误:
Exception 'callbackMethod:(RCTResponseSenderBlock)callback is not a recognized Objective-c
method.'
Run Code Online (Sandbox Code Playgroud)
但是,我在文档中找不到任何问题。有人可以提供一些帮助吗?