我正在学习Swift,并尝试编写一个小应用程序。
我正在尝试使用导航将视图推送到webview。但是现在它根本不动,这是我的代码:
在表格视图中,我点击每个单元格将让我转到其他视图:
类ViewController:UIViewController,UITableViewDelegate,UITableViewDataSource { @IBOutlet var myTable:UITableView! var items:[String] = [" Date Picker"," Data of Data"," Slider"," Show Image",&# 34; Web显示"];
override func viewDidLoad() {
super.viewDidLoad()
NSLog("Hello World at console");
var nib = UINib(nibName: "ListCell", bundle: nil)
myTable?.registerNib(nib, forCellReuseIdentifier: "ListCell")
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
switch indexPath.row
{
case 0:
var goView = DatePickerViewController(nibName: "DatePickerViewController", bundle:nil)
self.navigationController?.pushViewController(goView, animated: false)
println(items[indexPath.row])
break
case 1:
var goView = DetailViewController(nibName: "DetailViewController", bundle:nil)
self.navigationController?.pushViewController(goView, animated: false)
println(items[indexPath.row])
break
case 2:
var goView = SliderViewController(nibName: "SliderViewController", bundle:nil)
self.navigationController?.pushViewController(goView, animated: false)
println(items[indexPath.row])
break
case 3:
var goView = ImageCalleryViewController(nibName: "ImageCalleryViewController", bundle:nil)
self.navigationController?.pushViewController(goView, animated: false)
println(items[indexPath.row])
break
case 4:
// var goView = WebDisplayViewController(nibName: "WebDisplayViewController", bundle:nil)
// self.navigationController?.pushViewController(goView, animated: false)
self.navigationController?.pushViewController(WebDisplayViewController(), animated: false);
println(WebDisplayViewController());
println(items[indexPath.row])
break
default:
return;
}
}
这是我在网络视图中的代码。我试图不使用Interface Builder(想要先习惯语法)
import Foundation
import UIKit
class WebDisplayViewController: UIViewController {
override func viewDidLoad() {
var webView = UIWebView (frame: CGRectMake(20, 240, 280, 310));
var url = NSURL(string :"http://developer.xamarin.com/guides/cross-platform/Application_Fundamentals/Web_Services/");
var request = NSURLRequest(URL: url!);
webView.scalesPageToFit = true;
webView.loadRequest(request);
self.view.addSubview(webView);
println("I am in Web");
super.viewDidLoad()
}
}
AppDelegate中的代码:
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let mainVC = ViewController()
let navigationVC = UINavigationController(rootViewController: mainVC)
window?.rootViewController = navigationVC;
window?.makeKeyAndVisible()
return true
}
请告诉我有什么问题。