Permalink
Browse files

safe_remove_from_superview helper function

  • Loading branch information...
ettore committed Dec 3, 2011
1 parent 47f791a commit cf28ce978f1d4bbbad80e84ef0974a031356cdcb
Showing with 27 additions and 0 deletions.
  1. +19 −0 clcg_gfx.h
  2. +8 −0 clcg_gfx.m
View
@@ -29,8 +29,22 @@
*/
+#ifndef CLCG_GFX_H_
+#define CLCG_GFX_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#import <Foundation/Foundation.h>
+
+/**
+ * Before calling removeFromSuperview, ensures that the object is an actual
+ * UIView, otherwise it does nothing.
+ */
+void clcg_safe_remove_from_superview(id view);
+
/**
* Does a snapshot of a view appending a title below it.
*/
@@ -85,3 +99,8 @@ UIActivityIndicatorView *clcg_new_spinny(CGFloat size);
*/
void clcg_attach_spinny2cell(CGFloat size, UITableViewCell *cell);
+#ifdef __cplusplus
+}
+#endif
+
+#endif
View
@@ -33,6 +33,14 @@ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#import "clcg_gfx.h"
+void clcg_safe_remove_from_superview(id view)
+{
+ if (view && [view isKindOfClass:[UIView class]] && [view superview]) {
+ [view removeFromSuperview];
+ }
+}
+
+
//TODO-XX make font name and height parameters
UIImage *clcg_do_snapshot(UIView *v, NSString *title)
{

0 comments on commit cf28ce9

Please sign in to comment.