Statt Buttons eine TableView verwenden

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Statt Buttons eine TableView verwenden

    In diesem Code wird in der viewDidLoad ein Link für den Anfang der WebView geladen
    Es ist dann möglich über 3 verschiedene Buttons die Links in der WebView zu ändern

    Wäre folgendes möglich, wenn ja, wie?
    Statt den 3 UIButtons 3 cells, also eine TableView zu erstellen?
    Also dass ich dann über die TableView(Cell) den Link in der WebView verändere

    C-Quellcode

    1. - (void)viewDidLoad
    2. {
    3. [super viewDidLoad];
    4. // Get the path of the resource file
    5. NSString* path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"news/en/"];
    6. // Convert it to the NSURL
    7. NSURL* address = [NSURL fileURLWithPath:path];
    8. // Create a request to the resource
    9. NSURLRequest* request = [NSURLRequest requestWithURL:address];
    10. //Load the request in the UIWebView.
    11. [self->webbilder2 loadRequest:request];
    12. }
    13. -(IBAction)link1 {
    14. // Get the path of the resource file
    15. NSString* path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"news/ge/"];
    16. // Convert it to the NSURL
    17. NSURL* address = [NSURL fileURLWithPath:path];
    18. // Create a request to the resource
    19. NSURLRequest* request = [NSURLRequest requestWithURL:address];
    20. //Load the request in the UIWebView.
    21. [self->webbilder2 loadRequest:request];
    22. }
    23. -(IBAction)link2 {
    24. // Get the path of the resource file
    25. NSString* path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"news/fr/"];
    26. // Convert it to the NSURL
    27. NSURL* address = [NSURL fileURLWithPath:path];
    28. // Create a request to the resource
    29. NSURLRequest* request = [NSURLRequest requestWithURL:address];
    30. //Load the request in the UIWebView.
    31. [self->webbilder2 loadRequest:request];
    32. }
    33. -(IBAction)link3 {
    34. // Get the path of the resource file
    35. NSString* path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"news/ar/"];
    36. // Convert it to the NSURL
    37. NSURL* address = [NSURL fileURLWithPath:path];
    38. // Create a request to the resource
    39. NSURLRequest* request = [NSURLRequest requestWithURL:address];
    40. //Load the request in the UIWebView.
    41. [self->webbilder2 loadRequest:request];
    42. }
    Alles anzeigen
  • klar kannst du - ob das aber bei 3 buttons sinnvoll ist, ist wieder eine andere frage.

    den code würde ich aber arg verienheitlichen:

    also eine methode loadIndexHtmlInFolder und die rufst du dann in den 3 methoden mit dem jeweiligen wert auf.
    bzw würd ich sogar nur eine methode verweden und den buttons einfach als representedObject den folder setzen.