2012-02-23 58 views
1

長時間潛伏第一次海報轉換簡單的Android項目在Xcode中運行

我有一個簡單的android項目,我被要求在iOS上運行。我不是在所有的程序員,只是一個網絡傢伙,是快速志願者的任務...

所以,這是我一直在考慮什麼去上班關閉(在Eclipse項目):

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // Add Click listeners for all buttons 
    View firstButton = findViewById(R.id.button1); 
    firstButton.setOnClickListener(this); 
    View secondButton = findViewById(R.id.button2); 
    secondButton.setOnClickListener(this); 
    View thirdButton = findViewById(R.id.button3); 
    thirdButton.setOnClickListener(this); 
    View fourthButton = findViewById(R.id.button4); 
    fourthButton.setOnClickListener(this); 
    View fifthButton = findViewById(R.id.button5); 
    fifthButton.setOnClickListener(this); 
} 

// Process the button click events 
public void onClick(View v) { 

    //based on the button clicked display associated html file 
    //html files are located under the assets folder 
    switch(v.getId()){ 
     case R.id.button1: 
      Intent j = new Intent(this, Webscreen.class); 
      j.putExtra(Webscreen.URL, "file:///android_asset/deliver.html"); 
      startActivity(j); 
     break; 

     case R.id.button2: 
      Intent k = new Intent(this, Webscreen.class); 
      k.putExtra(Webscreen.URL, "file:///android_asset/return.html"); 
      startActivity(k); 
     break; 

     case R.id.button3: 
      Intent l = new Intent(this, Webscreen.class); 
      l.putExtra(Webscreen.URL, "file:///android_asset/updating.html"); 
      startActivity(l); 
     break; 

     case R.id.button4: 
      Intent m = new Intent(this, Webscreen.class); 
      m.putExtra(Webscreen.URL, "file:///android_asset/repair.html"); 
      startActivity(m); 
     break; 

     case R.id.button5: 
      Intent n = new Intent(this, Webscreen.class); 
      n.putExtra(Webscreen.URL, "file:///android_asset/vendor.html"); 
      startActivity(n); 
     break; 
    } 

因此,所有的功能都是在屏幕上顯示5個按鈕,點擊後它們會打開一個本地html文件。

任何人都有一些很好的例子來看待在Xcode中做類似的事情嗎?我正在嘗試使用Web視圖,但我沒有太多運氣。我設法得到了一些與記分板一起工作的東西,但是這個應用程序在以前的iOS版本中必須有價值,而不僅僅是5.0。

在此先感謝任何/所有的幫助!

回答

0

嗯,你說你根本不是程序員......所以我甚至不知道從哪裏開始。最簡單的方法是在Safari中簡單地打開這些html文件。所有你需要的是一個帶有html文件的html服務器。這是你如何能做到這一點:

NSString *urlString = [NSString stringWithFormat:@"http:///yourdomain/deliver.html"]; 
NSURL * url = [NSURL URLWithString:urlString]; 
[[NSWorkspace sharedWorkspace] openURL:url]; 

如果你想使用網頁視圖,你這是怎麼加載文件到視圖:

-(void)loadDocument:(NSString*)documentName inView:(UIWebView*)webView 
{ 
    NSString *path = [[NSBundle mainBundle] pathForResource:documentName ofType:nil]; 
    NSURL *url = [NSURL fileURLWithPath:path]; 
    NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
    [webView loadRequest:request]; 
} 

// Calling -loadDocument:inView: 
[self loadDocument:@"deliver.html" inView:self.webview]; 

您可以通過添加HTML文件到您的項目只需將它們拖放到Xcode左側的導航器列表中即可。將出現一張表。記得選擇「複製文件...」並選中目標旁邊的複選框。

webView變量是您在Interface Builder中定義的Web視圖。你此設置使用網點: https://developer.apple.com/library/mac/#recipes/xcode_help-interface_builder/CreatingOutlet.html

編輯:上一個按鈕,點擊時可以觸發方法使用動作。 在這裏,您可以瞭解更多關於動作的信息: https://developer.apple.com/library/ios/#documentation/IDEs/Conceptual/Xcode4TransitionGuide/InterfaceBuilder/InterfaceBuilder.html