繁体   English   中英

如何使用在main.storyboard中创建的原型单元阵列填充右侧的swreveal视图控制器

[英]How can i populate the right swreveal view controller with an array of prototype cells created in main.storyboard

我是新的堆栈溢出,这是我的第一篇文章,所以请耐心等待我!

我设置了sw_rear和sw_front,它们完美运行。

然而,当我尝试创建一个填充了原型单元格的表格视图,我的sw_right链接到一个阵列,从我在sw_rear中的那个单独分离,我发现当我尝试滑动甚至按下按钮访问正确的菜单时,应用程序崩溃而没有任何错误打印到日志。

(我在2个单独的快速文件中有2个数组,后面的vc和右边的VC链接到2个单独的表格视图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中构建的自定义原型单元格将填充我的列表。

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

我知道那部分很好,我只是坚持使用代码。

在我的根视图控制器中运行此代码,它就像一个魅力所以没有问题。

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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM