ios - 我如何使用在 main.storyboard 中创建的原型(prototype)单元格数组填充正确的 swreveal View Controller

标签 ios swift xcode uitableview swrevealviewcontroller

我是 stack overflow 的新手,这是我的第一篇文章,所以请耐心等待!

我设置了 sw_rear 和 sw_front,它们运行良好。

然而,当我尝试为我的 sw_right 创建一个包含原型(prototype)单元格的表格 View 时,我发现当我尝试滑动甚至按下按钮以访问正确的菜单时,应用程序链接到一个与我的 sw_rear 中的数组分开的数组崩溃,没有任何错误打印到日志中。

(我在 2 个单独的 swift 文件中有 2 个数组 rearVc 和 rightVC 链接到 2 个单独的 TableView sw_rear 和 sw_right)

上周我在网上搜索过(我所有的谷歌超链接都是紫色的!!)但似乎根本找不到答案。我认为将此代码(在我的后显示表 vc 中找到)复制到我的右表 vc 中会起作用,但不幸的是它不起作用!

(以 SWIFT 编码,仅供引用,我使用了 swrevealvc 的桥接头,因为我不知道 obj c)

import Foundation

class rearTableVC: UITableViewController {

var rearTableArray = [String]()

override func viewDidLoad() {

    rearTableArray = ["a", "b", "c", "d", "e", "f"]

}

    override func tableView(tableView: UITableView,   numberOfRowsInSection section: Int) -> Int {
    return rearTableArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(rearTableArray[indexPath.row], forIndexPath: indexPath) as UITableViewCell

    cell.detailTextLabel?.text = rearTableArray[indexPath.row]

    return cell
}
}

如您所见,我正在使用“cell.detailTextLabel?.text”,因此我在 main.storyboard 中构建的自定义原型(prototype)单元格将填充我的列表。

两者都正确链接到我的导航 Controller 以及其他场景。

我知道那部分没问题,我只是坚持使用代码。

在我的 Root View Controller 中,我正在运行这段代码,它运行起来非常棒,所以没有问题。

import Foundation

    class aVC : UIViewController {

@IBOutlet var menuButtonLeft: UIBarButtonItem!
@IBOutlet var menuButtonRight: UIBarButtonItem!

override func viewDidLoad() {


    menuButtonLeft.target = self.revealViewController()
    menuButtonLeft.action = #selector(SWRevealViewController.revealToggle(_:))

    menuButtonRight.target = self.revealViewController()
    menuButtonRight.action = #selector(SWRevealViewController.rightRevealToggle(_:))

    self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())

}

}

非常感谢任何帮助,我更愿意添加更多需要的信息!!

谢谢。

(对不起,我不能添加图片)

最佳答案

解决方案: 嗨,拐弯抹角几个小时后,我终于找到了一个解决方案,一个非常非常简单的解决方案。 在 SWRevealViewController.m 中缺少三个重要部分。我根本不知道 obj-c,但认为这些行缺少 rightViewController 的代码,所以在添加它们之后一切正常!

- (id)init
{
return [self initWithRearViewController:nil frontViewController:nil rightViewController:nil];
}

 - (id)initWithRearViewController:(UIViewController *)rearViewController frontViewController:(UIViewController *)frontViewController rightViewController:(UIViewController *)rightViewController;
{
self = [super init];
if ( self )
{
    [self _initDefaultProperties];
    [self     _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO];
    [self    _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO];
    [self _performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO];
}

我添加的只是

return [self initWithRearViewController:nil frontViewController:nil rightViewController:nil];

rightViewController:(UIViewController *)rightViewController;

_performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO];

线条

编辑 2(请求的信息)

#pragma mark - Init

- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if ( self )
{
    [self _initDefaultProperties];
}    
return self;
}


- (id)init
{
return [self initWithRearViewController:nil frontViewController:nil rightViewController:nil];
}


- (id)initWithRearViewController:(UIViewController *)rearViewController frontViewController:(UIViewController *)frontViewController rightViewController:(UIViewController *)rightViewController;
{
self = [super init];
if ( self )
{
    [self _initDefaultProperties];
    [self     _performTransitionOperation:SWRevealControllerOperationReplaceRearController withViewController:rearViewController animated:NO];
    [self _performTransitionOperation:SWRevealControllerOperationReplaceFrontController withViewController:frontViewController animated:NO];
    [self _performTransitionOperation:SWRevealControllerOperationReplaceRightController withViewController:rightViewController animated:NO];
}
return self;
}

关于ios - 我如何使用在 main.storyboard 中创建的原型(prototype)单元格数组填充正确的 swreveal View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39094575/

相关文章:

ios - 如何动态跟踪场景中的 SCN 节点以进行删除?

ios - UIView 上的 UIStoryboard 约束

objective-c - NSOutlineView 和 isItemExpandable 在 Swift 中不起作用

ios - Swift:NSBundle 在尝试设置为 filePath 时总是设置为 nil

objective-c - 我的字符串怎么可能不安全?

ios - style fontWeight 和 fontStyle react-native 不能一起工作

ios - 使用自定义动画在 View 的两种状态之间进行动画处理

ios - 表格 View 单元格保持突出显示

ios - Swift:我如何在应用程序关闭时保留数据

swift - '[任何对象] !' is not convertible to ' 序列类型'