我有一个带有类文件ViewController.h& m的viewController,它包含一个UIView,但是UIView有一个自定义类文件drawView.h& m,它通过#import“drawView.m”引用到ViewController.m中。我想在ViewController.m中设置一个UIColor变量(可以是任何颜色)并传递它并在drawView.m中读取它。
我知道如何将变量从一个视图控制器类文件传递到另一个ViewController类文件,但它似乎没有相同的方式将它传递给UIView类文件。请帮忙。
答案 0 :(得分:0)
您可以使用UserDafaults保存 $(document).ready(function () {
console.log(">>>1");
//--
action.setCallback(this, function(a) {
if (a.getState() === "SUCCESS") {
result = a.getReturnValue();
console.log(result);
//---=
var editActionOptions = {
keys: true,
url:null,
oneditfunc: function (rowid) {
console.log("row with rowid=" + rowid + " is editing.");
},
aftersavefunc: function (rowid, response, options) {
console.log("row with rowid=" + rowid + " is successfuly modified.");
}
};
//-------------------------------------------------------------------------------------------------------
$("#jqGrid").jqGrid({
editurl: 'clientArray',
datatype: "local",
data:result,
colModel: [
{
label: "Edit Actions",
name: "actions",
width: 100,
formatter: "actions",
formatoptions: {
keys: true,
editOptions: {},
addOptions: {},
delOptions: {}
}
},
{
labe: 'ID',
name: 'empid',
width: 75
},
{
label : 'Name',
name: 'Name',
width: 140,
editable: true // must set editable to true if you want to make the field editable
},
{
label: 'dob',
name: 'dob',
width: 100,
editable: true
},
{
label: 'dln',
name: 'dln',
width: 120,
editable: true
}
],
sortname: 'empid',
loadonce: true,
onSelectRow: editRow,
onSave:onSaveRow,
editParams: editActionOptions,
width: 780,
height: 400,
rowNum: 150,
pager: "#jqGridPager"
});
//------------------------------------------------------------------------------------------------------
} else if (a.getState() === "ERROR") {
$A.log("Errors", a.getError());
}
});
$A.enqueueAction(action);
var lastSelection;
function editRow(id) {
console.log(id);
if (id && id !== lastSelection) {
var grid = $("#jqGrid");
grid.jqGrid('restoreRow',lastSelection);
grid.jqGrid('editRow',id, {keys: true} );
lastSelection = id;
}
};
function onSaveRow(id){
console.log(id);
}
中的UIColor
并获取颜色并在自定义课程ViewController
中使用。
检查以下代码:
将UIView
保存到UIColor
UserDafaults
从NSData *colorData = [NSKeyedArchiver archivedDataWithRootObject:[UIColor blueColor]];
[[NSUserDefaults standardUserDefaults] setObject:colorData forKey:@"myColor"];
获取UIColor
:
UserDafaults
答案 1 :(得分:0)
尝试在ViewController viewWillApear或viewDidLoad中设置颜色,或者在viewWillApear或viewDidLoad之后设置颜色,以确保正确加载drawView。
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Any color that u want to use
UIColor * color =[UIColor redColor];
if([self.drawView)
{
// applyeColor is drawview's custom method
[self.drawView applyColor:color];
}
else
{
NSlog (@"drawView is nil");
}
}