title: Bookmark menu with UITableview Thread 1 : signal SIGABRT error
body: <p>I have the following problem. I created a fully functional browser, but when I use the "add bookmark function" or the "show bookmark function", I get always a Thread1: signal SIGABRT error. I tried everything since 8 hours and I can't find the solution. Can someone take a look at my code at give me a clue how to fix this? I'm very frustrated and hope that someone can help, because I really don't know what to do. I think it has something to do with the "forKey" tags, but I'm not sure. Here is my code:</p>
  
  <p>AppDelegate.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @class ViewController;
  
  @interface AppDelegate : NSObject &lt;UIApplicationDelegate&gt;
  
  @property (strong, nonatomic) UIWindow *window;
  
  
  @end
  </code></pre>
  
  <p>AppDelegate.m:</p>
  
  <pre><code>#import "AppDelegate.h"
  #import "ViewController.h"
  
  @interface AppDelegate ()
  
  @end
  
  @implementation AppDelegate
  
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
  NSMutableDictionary* dictionary = [NSMutableDictionary dictionary];
  [dictionary setObject:[NSMutableArray array] forKey:@"medis"];
  [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
  return YES;
  }
  
  - (void)applicationWillResignActive:(UIApplication *)application {
  
  }
  
  - (void)applicationDidEnterBackground:(UIApplication *)application {
  
  
  }
  
  - (void)applicationWillEnterForeground:(UIApplication *)application {
  
  }
  
  - (void)applicationDidBecomeActive:(UIApplication *)application {
      }
  
  - (void)applicationWillTerminate:(UIApplication *)application {
  }
  
  @end
  </code></pre>
  
  <p>ViewController.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import "FavoritenController.h"
  
  @interface ViewController : UIViewController &lt;UITextFieldDelegate,   UIWebViewDelegate, UIActionSheetDelegate&gt;
  
  {
  
  
  UIWebView *Webseite;
  UIBarButtonItem *backButton;
  UIBarButtonItem *forwardButton;
  UITextField *textField;
  UIBarButtonItem *refreshButton;
  NSString* urlBeforeEditing;
  
  
  FavoritenController* favoritenController;
  
  }
  @property (nonatomic, retain) IBOutlet UITextField *textField;
  @property (weak, nonatomic) IBOutlet UIBarButtonItem *onlinetauscher;
  @property (nonatomic, retain) IBOutlet UIWebView *Webseite;
  @property ( nonatomic, retain) IBOutlet UIBarButtonItem   *refreshButton;
  @property ( nonatomic, retain) IBOutlet UIBarButtonItem *backButton;
  @property (nonatomic, retain) IBOutlet UIBarButtonItem *forwardButton;
  
  - (IBAction)onlinetauscher:(UIBarButtonItem *)sender;
  
  - (IBAction)pressRefresh:(UIBarButtonItem *)sender;
  
  - (IBAction)zeigeMedikamente:(id)sender;
  - (IBAction)hinzufuegen:(id)sender;
  
  @end
  </code></pre>
  
  <p>ViewController.m:</p>
  
  <pre><code>#import "ViewController.h"
  
  
  
  @interface ViewController ()
  
  @end
  
  @implementation ViewController
  @synthesize Webseite;
  @synthesize refreshButton;
  @synthesize textField;
  @synthesize backButton;
  @synthesize forwardButton;
  
  - (void)loadString:(NSString*)urlString{
      NSRange range = [urlString rangeOfString:@"."];
      NSURLRequest* request;
  
      if (range.location != NSNotFound) {
          if ([urlString hasPrefix:@"http://"] == YES || [urlString hasPrefix:@"https://"] == YES) {
              request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
          } else {
              NSString* string = [NSString stringWithFormat:@"https://%@", urlString];
              request = [NSURLRequest requestWithURL:[NSURL URLWithString:string]];
          }
      } else {
          NSString* tempString = [urlString stringByAddingPercentEscapesUsingEncoding:NSISOLatin1StringEncoding];
          NSString* string = [NSString stringWithFormat:@"https://www.google.de/search?q=%@", tempString];
          request = [NSURLRequest requestWithURL:[NSURL URLWithString:string]];
      }
  
  
      [Webseite loadRequest:request];
  
  }
  -(void)loadBookmark:(NSString*)urlString {
   [self loadString:urlString];
   self.textField.text = urlString;
   }
  -(void)cancel {
      [textField resignFirstResponder];
  }
  
  #pragma mark -
  #pragma mark Delegates
  
  -(BOOL)textFieldShouldReturn:(UITextField *)atextField { //?
      [self loadString:textField.text];
      [textField resignFirstResponder];
      return YES;
  }
  
  -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)
  navigationType{
  
      textField.text = [request.URL absoluteString];
      [textField resignFirstResponder];
      return YES;
  }
  
  -(void) webViewDidStartLoad:(UIWebView *)awebView{
      [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
  
  }
  -(void) webViewDidFinishLoad:(UIWebView *)awebView{
      [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
      if ([awebView canGoBack] == YES){
          [backButton setEnabled:YES];
      }else{
          [backButton setEnabled:NO];
      }
      if([awebView canGoForward] == YES){
          [forwardButton setEnabled:YES];
      }else{
          [forwardButton setEnabled:NO];
      }
  
  
  }
  #pragma mark - View lifecycle
  
  - (void)viewDidLoad {
      [super viewDidLoad];
     forKeyPath:@"contentOffset" options:0 context:NULL]; //erzeugt sigabrt
      favoritenController = [[FavoritenController alloc] init];
              NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
          NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
  
              NSURL *scriptUrl = [NSURL URLWithString:@"thewebsite"];
          NSData *urlData = [NSData dataWithContentsOfURL:scriptUrl];
      if (urlData) {
          NSLog(@"Device is connected to the internet");
           NSURL *myURL = [NSURL URLWithString:@"thewebsite"];
          NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
          [Webseite loadRequest:myRequest];
      }
      else {
           NSLog(@"Device is not connected to the internet");
          [urlData writeToFile:filePath atomically:YES];
      [Webseite loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
      }
  
  
  
      }
  
  
  
  - (IBAction)onlinetauscher:(UIBarButtonItem *)sender {
      NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
      NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],@"index.html"];
  
  
      NSURL *scriptUrl = [NSURL URLWithString:@"thewebsite"];
      NSData *urlData = [NSData dataWithContentsOfURL:scriptUrl];
      if (urlData) {
          NSLog(@"Device is connected to the internet");
    NSURL *myURL = [NSURL URLWithString:@"thewebsite"];
          NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
          [Webseite loadRequest:myRequest];
      }
      else {
          NSLog(@"Device is not connected to the internet");
          [urlData writeToFile:filePath atomically:YES];
          [Webseite loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];
      }
  
  }
  - (void)viewDidUnload
  {
      [self setWebseite:nil];
      [self setTextField:nil];
      [self setRefreshButton:nil];
      [self setBackButton:nil];
      [self setForwardButton:nil];
  
  
  
      [super viewDidUnload];
          }
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
      return YES;
  }
  
  
  - (IBAction)pressRefresh:(UIBarButtonItem *)sender {
      [self loadString:textField.text];
  }
  
  - (IBAction)zeigeMedikamente:(UIBarButtonItem *)sender {
  
  
      UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:favoritenController];
      favoritenController.delegatee = self;
      [self presentModalViewController:navController animated:YES];
      [favoritenController newMethod];
  }
  
  
  - (IBAction)hinzufuegen:(UIBarButtonItem *)sender {
  
  
          NSString* title = [Webseite stringByEvaluatingJavaScriptFromString:@"document.title"];
       NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:title, @"title", textField.text, @"url", nil];          
       [favoritenController.medis addObject:dict];
  
       [favoritenController.tableView reloadData];
       UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Bookmark added" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
       [alertView show];
  
       [[NSUserDefaults standardUserDefaults] setObject:favoritenController.medis forKey:@"medis"];
  }
  
  
  @end
  </code></pre>
  
  <p>FavoritenController.h:</p>
  
  <pre><code> #import &lt;UIKit/UIKit.h&gt;
  
  @interface FavoritenController : UITableViewController {
      NSMutableArray* medis;
      __unsafe_unretained NSObject* delegatee;
  }
  
  @property (nonatomic, retain) NSMutableArray* medis;
  @property (nonatomic, assign) NSObject* delegatee;
  
  -(void) newMethod;
  @end
  </code></pre>
  
  <p>FavoritenController.m:</p>
  
  <pre><code>#import "FavoritenController.h"
  
  @interface FavoritenController ()
  
  @end
  
  @implementation FavoritenController
  @synthesize medis, delegatee;
  -(id)init
  {
      self = [super init];
      if(self){
          if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"medis"] count] != 0) {
              self.medis = [[NSUserDefaults standardUserDefaults] objectForKey:@"medis"];
          } else {
              self.medis = [[NSMutableArray alloc] init];
          }
      }
      return self;
  }
  - (void)dealloc
  {
      self.medis = NULL;
  
  
  }
  
  
  - (void) cancel {
      [self dismissModalViewControllerAnimated:YES];
  }
  #pragma mark - View lifecycle
  -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
      return YES;
  }
  -(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
      NSDictionary* dict = [medis objectAtIndex:sourceIndexPath.row];
      [medis removeObjectAtIndex:sourceIndexPath.row];
      [medis insertObject:dict atIndex:destinationIndexPath.row];
  
      [[NSUserDefaults standardUserDefaults] setObject:self.medis forKey:@"medis"];
  
  }
  -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
      if (editingStyle == UITableViewCellEditingStyleDelete) {
          [medis removeObjectAtIndex:indexPath.row];
          [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade];
          [[NSUserDefaults standardUserDefaults] setObject:self.medis forKey:@"medis"];          }
  }
  -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
      return UITableViewCellEditingStyleDelete;
  }
  
  - (void)viewDidLoad {
      [super viewDidLoad];
      self.navigationItem.title = @"Meine Medikamente";
      [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action: @selector(cancel)]];
      medis = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"medis"] mutableCopy];
      [self.tableView reloadData];
      [self.navigationItem setRightBarButtonItem:self.editButtonItem];
  
  }
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
              return YES;
  }
  #pragma mark - Table view data source
  - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
      return 1;
  }
  
  - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  
      return [medis count];
  }
  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      static NSString *CellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
  
      }
  
              cell.textLabel.text = [[medis objectAtIndex:indexPath.row ] objectForKey:@"title"];
      cell.detailTextLabel.text = [[medis objectAtIndex:indexPath.row] objectForKey:@"url"];
      return cell;
  }
  
  
  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
      NSString* url = [[medis objectAtIndex:indexPath.row] objectForKey:@"url"];
       #pragma GCC diagnostic ignored "-Wundeclared-selector"
      if (self.delegatee &amp;&amp; [self.delegatee respondsToSelector:@selector(loadBookmark:)]) {
       [self.delegatee performSelector:@selector(loadBookmark:) withObject:url];
       }
      [self cancel];
  }
  
  
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
                  }
      return self;
  }
  
  
  
  
  
  
  
  
  
  - (void) newMethod{
      self.navigationItem.title = @"My Bookmarks";
      [self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action: @selector(cancel)]];
      medis = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"medis"] mutableCopy];
      [self.tableView reloadData];
  
  }
   @end
  </code></pre>
  
  <p>debug console:</p>
  
  <pre><code>* thread #1: tid = 0x2e6a, 0x0000000104ccc002 libsystem_kernel.dylib`__pthread_kill + 10, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
      frame #0: 0x0000000104ccc002 libsystem_kernel.dylib`__pthread_kill + 10
      frame #1: 0x0000000104c925c5 libsystem_pthread.dylib`pthread_kill + 90
      frame #2: 0x0000000104a32cec libsystem_c.dylib`abort + 129
      frame #3: 0x0000000104831051 libc++abi.dylib`abort_message + 257
      frame #4: 0x0000000104856ac9 libc++abi.dylib`default_terminate_handler() + 267
      frame #5: 0x0000000101cca046 libobjc.A.dylib`_objc_terminate() + 103
      frame #6: 0x000000010485426e libc++abi.dylib`std::__terminate(void (*)()) + 8
      frame #7: 0x0000000104853ef9 libc++abi.dylib`__cxa_rethrow + 99
      frame #8: 0x0000000101cc9f5e libobjc.A.dylib`objc_exception_rethrow + 40
      frame #9: 0x00000001021718e4 CoreFoundation`CFRunLoopRunSpecific + 676
      frame #10: 0x0000000105a0dad2 GraphicsServices`GSEventRunModal + 161
      frame #11: 0x00000001025fd610 UIKit`UIApplicationMain + 171
    * frame #12: 0x00000001017c5ddf Websitemobil`main(argc=1, argv=0x00007fff5e43c640) + 111 at main.m:14
      frame #13: 0x000000010498c92d libdyld.dylib`start + 1
  </code></pre>