我是Swift和ios开发人员的新手。我想创建一个侧面菜单,该单元事件将动态更改容器视图中的内容。但这似乎行不通。
我尝试了两种方法来更改容器视图的背景颜色
第一个是
func tableView (_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let vc2 = storyboard?.instantiateViewController(withIdentifier: "vc2") as? ViewController2
vc2?.view.backgroundColor = UIColor.white
}
第二种方法是
func tableView (_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
let vc2 = storyboard?.instantiateViewController(withIdentifier: "vc2") as? ViewController2
vc2?.changecolor()
}
和vc2
中func changecolor()
{
print(123)
self.view.backgroundColor = UIColor.purple
}
它将打印123,但不会更改背景色
如何更改其他视图控制器中的内容? (如果我不想删除当前容器视图并更改为另一个视图)
答案 0 :(得分:0)
//Create button on Sheet in dropdown
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Overwatch API Menu')
.addItem('Get Updated Stats','ovrstat')
.addToUi();
};
var nameCell = ["A2","A3","A4","A5"];
var rate = ["B2","B3","B4","B5"];
var i;
for (i = 0; i < 4; i = i + 1){
var rangeA = nameCell[i];
var rangeB = rate[i];
function ovrstat() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var name = sheet.getRange(rangeA).getValue();
// Call the Ovrstat API
var response = UrlFetchApp.fetch('https://ovrstat.com/stats/psn/'+name);
var json = response.getContentText();
var data = JSON.parse(json);
Logger.log(data.rating);
var sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange(rangeB).setValue([data.rating]);
};
};