Programmatically place objects in a window

walden systems, objective c, geolocation, ios, CLLocationManager, desiredAccuracy, distanceFilter, startUpdatingLocation, stopUpdatingLocation, delegate, iphone, picture, screen, swipe, iphone, thread, nsthread, uitableviewcell, uitableview, initwithFName, infocellcontroller, nsdate, nsdateformatter nsstring, uuid, time, sleep, uiimage, UIGraphicsBeginImageContext, drawinrect, cgrectmake, nsuserdefaults, standarduserdefaults, setobjectforkey, objectforkey, UIControlEventTouchUpInside
Objective-C defines a small but powerful set of extensions to the ANSI C programming language that enables sophisticated object-oriented programming. Objective-C is the native language for Cocoa programming—it’s the language that the frameworks are written in, and the language that most applications are written in. You can also use some other languages—such as Python and Ruby—to develop programs using the Cocoa frameworks. It’s useful, though, to have at least a basic understanding of Objective-C because Apple’s documentation and code samples are typically written in terms of this language.

Here is an example of adding an object programmatically in a window. In this example, a UIButton will be added to the window. In order to do this, we must instantiate a button, add an event handler to the button, give it some properties, have the event trigger a method, and add the button to the window. In this case, we use the event UIControlEventTouchUpInside to trigger some method, aMethod. In this example, we set the following properties to the new button; title, x coordinates, y coordinates, width and height of button.

1    UIButton *new_button = [UIButton buttonWithType:UIButtonTypeCustom];
2    [new_button addTarget:self 
3                   action:@selector(aMethod:)
4         forControlEvents:UIControlEventTouchUpInside];
5  
6    [new_button setTitle:@"Show View" forState:UIControlStateNormal];
7    new_button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
8    [view addSubview:new_button];