簡體   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