这是我的代码,从一个viewController导航到另一个viewControler,但我无法导航。数据是rest api nsobject数据,它存储来自rest api的类别作为名称,娱乐是类别。当我点击类别转到另一个viewController
public class Test
{
public static void main(String args[]) throws Exception
{
String[] answersArray = new String[4];
answersArray[0] = "OS";
answersArray[1] = "GOOD";
answersArray[2] = "CS";
answersArray[3] = "Cody";
List<String> answersList = new ArrayList<String>(Arrays.asList(answersArray));
final Random randomNumber = new Random();
final int low = 0;
int high = 0;
while(!answersList.isEmpty()){
high = answersList.size();
int result = randomNumber.nextInt(high - low) + low;
System.out.print(answersList.get(result) + " ");
answersList.remove(result);
}
}
}
答案 0 :(得分:0)
如果您使用情节提要,请使用此-
if let navigationObject = UIStoryboard(name: "storyboard_name", bundle: nil).instantiateViewController(withIdentifier: "viewcontroller_storyboardId") as? viewController_name {
navigationController?.pushViewController(navigationObject, animated: true)
}
答案 1 :(得分:0)
可能有以下原因
检查名称是否包含娱乐性或娱乐性作为字符串 值?表示区分大小写(作为测试,请检查并检查) data [indexPath.row] .name.lowerCased()==“娱乐” .lowerCased()
如果缺少嵌入,则缺少navigationController(未嵌入导航控制器) navigationController到您的根控制器。
尝试删除dismiss(animated: true, completion: nil)
答案 2 :(得分:0)
只需使用此
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if data[indexPath.row].name == "Entertainment" {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let whiteVC = storyboard.instantiateViewController(withIdentifier: "WhiteViewController") as! WhiteViewController
self.navigationController?.pushViewController(whiteVC, animated: true)
}
}