【问题标题】:Pass data from method to method在方法之间传递数据
【发布时间】:2015-06-12 05:23:25
【问题描述】:
- (void) getArrray : (NSArray*)arrray{
NSLog(@"Get Array %@",arrray);
}

-(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index
{
      draggableView.information.text = [exampleCardLabels objectAtIndex:index]
}

我希望将数组数据添加到 examplecardlabels 而不会干扰方法。如何从 getdata 方法获取数据到 createdraggable 方法

请帮助我。

【问题讨论】:

    标签: ios objective-c methods nsarray


    【解决方案1】:

    在此类中创建propertyglobal variable,然后在一个方法中设置它并在另一个方法中读取值。

    @implementation myClass 
    {
       NSArray* myArrayData;
    }
    
    - (void) getArrray : (NSArray*)arrray{
       NSLog(@"Get Array %@",arrray);
       myArrayData = array;
    }
    
    -(DraggableView *)createDraggableViewWithDataAtIndex:(NSInteger)index{
       draggableView.information.text = [myArrayData objectAtIndex:index];
    }
    }
    

    【讨论】:

    • 我尝试了某种方式,但我很困惑。你能解决吗?给我一个样品
    • 添加了更多细节,希望对您有所帮助?
    • 如果您需要更多帮助,我需要更多信息。您是否更改了所有 3 个地方?
    • 我从 github.com/cwRichardKim/TinderSimpleSwipeCards 导入了 tinder 卡片类到 swift 请下载这个并将数据从视图控制器传递到 dragabbleviewbackground 类。
    • var draggableBackground : DraggableViewBackground = DraggableViewBackground() draggableBackground.frame = self.view.frame draggableBackground.backgroundColor = UIColor.whiteColor() self.view.addSubview(draggableBackground) var brdarray: NSMutableArray = ["A ","B","C"] draggableBackground.initWithInitialArray(brdarray) 我是这样从视图控制器发送的
    猜你喜欢
    • 1970-01-01
    • 2016-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 2013-03-27
    • 1970-01-01
    相关资源
    最近更新 更多