Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add default target and selector to barButtonItem if one is not alread…

…y specified
  • Loading branch information...
commit a6db4d8a4f040027986c4127465475e12fc1b8e8 1 parent 177173e
Jin Budelmann authored February 01, 2013

Showing 1 changed file with 46 additions and 5 deletions. Show diff stats Hide diff stats

  1. 51  SVWebViewController/SVWebViewController.m
51  SVWebViewController/SVWebViewController.m
@@ -41,27 +41,52 @@ @implementation SVWebViewController
41 41
 - (UIBarButtonItem *)backBarButtonItem {
42 42
     
43 43
     if (!backBarButtonItem) {
44  
-        backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SVWebViewController.bundle/iPhone/back"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackClicked:)];
  44
+        backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SVWebViewController.bundle/iPhone/back"]
  45
+                                                             style:UIBarButtonItemStylePlain
  46
+                                                            target:nil
  47
+                                                            action:nil];
45 48
         backBarButtonItem.imageInsets = UIEdgeInsetsMake(2.0f, 0.0f, -2.0f, 0.0f);
46 49
 		backBarButtonItem.width = 18.0f;
47 50
     }
  51
+    
  52
+    if (backBarButtonItem.target == nil && backBarButtonItem.action == nil) {
  53
+        backBarButtonItem.target = self;
  54
+        backBarButtonItem.action = @selector(goBackClicked:);
  55
+    }
  56
+    
48 57
     return backBarButtonItem;
49 58
 }
50 59
 
51 60
 - (UIBarButtonItem *)forwardBarButtonItem {
52 61
     
53 62
     if (!forwardBarButtonItem) {
54  
-        forwardBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SVWebViewController.bundle/iPhone/forward"] style:UIBarButtonItemStylePlain target:self action:@selector(goForwardClicked:)];
  63
+        forwardBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"SVWebViewController.bundle/iPhone/forward"]
  64
+                                                                style:UIBarButtonItemStylePlain
  65
+                                                               target:nil
  66
+                                                               action:nil];
55 67
         forwardBarButtonItem.imageInsets = UIEdgeInsetsMake(2.0f, 0.0f, -2.0f, 0.0f);
56 68
 		forwardBarButtonItem.width = 18.0f;
57 69
     }
  70
+    
  71
+    if (forwardBarButtonItem.target == nil && forwardBarButtonItem.action == nil) {
  72
+        forwardBarButtonItem.target = self;
  73
+        forwardBarButtonItem.action = @selector(goForwardClicked:);
  74
+    }
  75
+    
58 76
     return forwardBarButtonItem;
59 77
 }
60 78
 
61 79
 - (UIBarButtonItem *)refreshBarButtonItem {
62 80
     
63 81
     if (!refreshBarButtonItem) {
64  
-        refreshBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(reloadClicked:)];
  82
+        refreshBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
  83
+                                                                             target:nil
  84
+                                                                             action:nil];
  85
+    }
  86
+    
  87
+    if (refreshBarButtonItem.target == nil && refreshBarButtonItem.action == nil) {
  88
+        refreshBarButtonItem.target = self;
  89
+        refreshBarButtonItem.action = @selector(reloadClicked:);
65 90
     }
66 91
     
67 92
     return refreshBarButtonItem;
@@ -70,16 +95,32 @@ - (UIBarButtonItem *)refreshBarButtonItem {
70 95
 - (UIBarButtonItem *)stopBarButtonItem {
71 96
     
72 97
     if (!stopBarButtonItem) {
73  
-        stopBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop target:self action:@selector(stopClicked:)];
  98
+        stopBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemStop
  99
+                                                                          target:nil
  100
+                                                                          action:nil];
  101
+    }
  102
+    
  103
+    if (stopBarButtonItem.target == nil && stopBarButtonItem.action == nil) {
  104
+        stopBarButtonItem.target = self;
  105
+        stopBarButtonItem.action = @selector(stopClicked:);
74 106
     }
  107
+    
75 108
     return stopBarButtonItem;
76 109
 }
77 110
 
78 111
 - (UIBarButtonItem *)actionBarButtonItem {
79 112
     
80 113
     if (!actionBarButtonItem) {
81  
-        actionBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButtonClicked:)];
  114
+        actionBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction
  115
+                                                                            target:nil
  116
+                                                                            action:nil];
82 117
     }
  118
+    
  119
+    if (actionBarButtonItem.target == nil && actionBarButtonItem.action == nil) {
  120
+        actionBarButtonItem.target = self;
  121
+        actionBarButtonItem.action = @selector(actionButtonClicked:);
  122
+    }
  123
+    
83 124
     return actionBarButtonItem;
84 125
 }
85 126
 

0 notes on commit a6db4d8

Please sign in to comment.
Something went wrong with that request. Please try again.