Posts Tagged iPhone

How to insert BOOL (boolean) value into ManagedObject in Core Data – iOS, iPad, iPhone

If you want to insert BOOL type into core data, you can do it with NSNumber’s member method +numberWithBool:

BOOL myBool = YES;
NSNumber *boolAsNumber = [NSNumber numberWithBool:myBool];
//now you can pass boolAsNumber into you managed object for storage!

If you want to retrieve a BOOL from NSNumber you can use -boolValue.

NSNumber *boolAsNumber = [NSNumber numberWithBool:NO];

BOOL getBool = [boolAsNumber boolValue];
Advertisements

, , , ,

Leave a comment

How to remove all views inside another view – iOS, iPhone, iPad

Let’s say we have a UIScrollView (myScrollView) in our application view. Inside UIScrollView we have couple of different subclasses of UIView (UILabel, UISegmentedControl, UIButton), like shown on the picture below.

Every subclass of UIView has a method subviews, which returns NSArray of all the views that are nested inside the view. Since UIScrollView is the subclass of UIView, we can do the following, for example inside viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
	UISeg
	for (UIView *aView in [myScrollView subviews]){
		NSLog(@"Class: %@", [aView class]);
	}
}
//Returnes 
//Class: UISegmentedControl
//Class: UILabel
//Class: UILabel
//Class: UILabel
//Class: UIRoundedRectButton
//Class: UITextField
//Class: UIImageView
//Class: UIImageView

Now if we wanted to delete all the subviews inside UIScrollView we would do

[aView removeFromSuperview];

and thus our UIScrollView would now be empty.

If we wanted to remove just UILabels from our UIScrollView we would do:

if ([aView isKindOfClass:[UILabel class]]){
			[aView removeFromSuperview];
		}

, , , ,

2 Comments

How to trim NSString in Objective C 2.0 – iOS, iPad, iPhone

When you want to trim a NSString in Objective C you can use NSString’s method stringByTrimmingCharactersInSet and passing it a [NSCharacterSet whitespaceAndNewlineCharacterSet] characterSet. This will trim your NSString from all newline and whitespace characters.

NSString *trimMe = @"    Trim this string      ";
trimMe = [trimMe stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSLog(@"Trimmed String: ++%@++", trimMe);
//returnes Trimmed String: ++Trim this string+++

You can also trim just whitespace by passing [NSCharacterSet whitespaceCharacterSet] or trim just newline characters by passing [NSCharacterSet newlineCharacterSet]

, , , , ,

1 Comment

Social Calc just released on the App Store

My first app that I submitted to the App Store was just approved. It can be found on: Social Calc

Social Calc calculates how two names get along for love, friendship, business, kids and partying.

Algorithm to calculate percentage is what we used when we were kids in elementary school, it was fun then and I guess it is still fun now (after 20 years).

Application consistis of 5 calculators:

  • Love Calculator
  • Friendship Calculator
  • Business Partner Calculator
  • Kids Calculator
  • Party Calculator
 

, , , ,

Leave a comment

Hide Status Bar in iPhone application, or change it’s style

What do you do to hide the status bar in iPhone application. If you build your views in Interface builder, you can set the status bar to None, but notice that above status bar menu it says: Simulated Interface Elements. That means, that it will only show a change in Interface Builder but not in a compiled application.

You have two options to hide the status bar, one is by editing info.plist file you have (typically in Resources Group). You can either open it up in TextEdit (or any other text editor) and add this value under dict XML tag:

<key>UIStatusBarHidden</key>
<true />

Other option is to open info.plist file by double clicking it and adding a new variable to the Information Property List. And under key type (or select from drop down menu) Status bar is initially hidden and check the checkbox (thus setting it’s property to true).

Last option is to do it programmatically inside one of your classes by:

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

By changing BOOL value of setStatusBarHidden to NO, you are able to show the hidden status bar:

[[UIApplication sharedApplication] setStatusBarHidden:NO animated:NO];

If you want to change the style of iPhone status bar you can once again edit info.plist and add for Opaque black style the following:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackOpaque</string>

for Transparent black style (alpha of 0.5) add:

<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleBlackTranslucent</string>

Again you can add status bar style by double clicking info.plist and selecting from dropdown menu Status bar style as Key and selecting prefered style as the value (again from the dropdown).

,

Leave a comment