долгое время lurker первый раз плакат
У меня есть простой андроид-проект, с которым меня попросили запустить iOS. Я вовсе не программист, просто парень в сети, который должен быстро добровольно выполнять задания...
Итак, это то, что мне дали работать (в проекте затмения):
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? Я пытаюсь работать с веб-представлением, но пока у меня не слишком много удачи. Мне удалось получить что-то вроде работы с табло, но это приложение должно быть ценным в предыдущих версиях iOS, а не только в версии 5.0.
Заранее спасибо за любую/любую помощь!
Ну, вы говорите, что вы совсем не программист... Поэтому я даже не знаю, с чего начать. Самый простой способ - просто открыть эти html файлы в Safari. Все, что вам понадобится, это html-сервер с html файлами. Так вы можете это сделать:
NSString *urlString = [NSString stringWithFormat:@"http:///yourdomain/deliver.html"];
NSURL * url = [NSURL URLWithString:urlString];
[[NSWorkspace sharedWorkspace] openURL:url];
Если вы хотите использовать webView, так вы загружаете файлы в представление:
-(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. Появится лист. Не забудьте выбрать "copy file..." и установите флажок рядом с вашей целью.
Переменная webView - это веб-просмотр, определенный вами в Interface Builder. Вы устанавливаете это с помощью выходов: 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