Thursday, December 29, 2011
Add UIBarButton item into a UIToolBar
Tuesday, November 29, 2011
Automatic Reference Counting (ARC)
Thursday, October 13, 2011
What Have You Tried?
This of course isn’t specific to software developers, but that’s my field and it’s thus the area in which I’m most familiar with the issue which motivated me to write this. I’m (sadly) quite sure that it applies to your own industry too, whatever that might be.
http://mattgemmell.com/2008/12/08/what-have-you-tried/
Stop Activity Indicator in Status Bar ?
Implement the
UIWebViewDelegate in your class file that holds the UIWebView ,and insert the following two methods:
In the start method, place your:
... and in the finish, place:
Hope this helps! |
Wednesday, October 05, 2011
Thursday, September 22, 2011
Friday, September 16, 2011
Thursday, September 08, 2011
Gdata XMl Parsing simply
How to Parse a attribute using GDATA xml Parser
NSInteger type=[[(GDataXMLNode *)[[urls objectAtIndex:i]
attributeForName:@"type"] stringValue] intValue];
NSInteger bit_stream=[[(GDataXMLNode *)
[[urls objectAtIndex:i]attributeForName:@"bit_stream"]
stringValue] intValue];
Thursday, August 25, 2011
Friday, August 12, 2011
How to find the hardware version in iOS
+ (NSString *)getSysInfoByName:(char *)typeSpecifier {
size_t size;
sysctlbyname(typeSpecifier, NULL, &size, NULL, 0);
char *answer = malloc(size);
sysctlbyname(typeSpecifier, answer, &size, NULL, 0);
NSString *results = [NSString stringWithCString:answer encoding: NSUTF8StringEncoding];
free(answer);
return results;
}
// to get the hardware version, we need to pass the argument hw.machine
[ClassName getSysInfoByName:"hw.machine"];
//getSysInfoByName is class method so we need to call by class name
Determine device (iPhone, iPod Touch) with iPhone SDK
NSString *deviceType = [UIDevice currentDevice].model;
if([deviceType isEqualToString:@"iPhone"])
Tuesday, August 09, 2011
Download, Create and Display Image from URL
NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:URL]];
UIImage *img=[UIImage imageWithData:data];
UIImageView* imageView = [[UIImageView alloc] initWithImage:img];
[self.view addSubview:imageView];
Tuesday, August 02, 2011
Create JSON Object Manually without using SBJSON in iOS SDK
+(NSString *)createJSONString:(NSDictionary *) dictionary
{
NSArray *jsonKeyArray = [dictionary allKeys];
NSArray *jsonKeyValue = [dictionary allValues];
NSString *jsonString = @"{";
for (int j=0; j<[jsonKeyArray count ]; j++) {
NSDictionary *dictFromArray = [jsonKeyValue objectAtIndex:j];
NSArray *keyArray = [dictFromArray allKeys];
jsonString = [NSString stringWithFormat:@"%@\"%@\":",jsonString, [jsonKeyArray objectAtIndex:j]];
NSArray *valueArray = [dictFromArray allValues];
// to check its empty dictionary
if ([keyArray count] != 0) {
for (int i = 0; i<[keyArray count];i++) {
if (i == 0) {
jsonString =[NSString stringWithFormat:@"%@{ \"%@\": \"%@\", ",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];
}//to check lost element of single dictionary
else if((i == [keyArray count]-1) ) {
if (j != [jsonKeyArray count]-1) {
// to check whether last element combined dictionary
jsonString =[NSString stringWithFormat:@" %@ \"%@\":\"%@\" },",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];
}else
{
jsonString =[NSString stringWithFormat:@" %@ \"%@\":\"%@\" }",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];
}
}else {
jsonString =[NSString stringWithFormat:@"%@ \"%@\":\"%@\", ",jsonString,[keyArray objectAtIndex:i],[valueArray objectAtIndex:i]];
}
}
}else {
if (j != [jsonKeyArray count]-1) {
jsonString =[NSString stringWithFormat:@"%@{},",jsonString];
}else
{
jsonString =[NSString stringWithFormat:@"%@{}",jsonString];
}
}
}
jsonString =[NSString stringWithFormat:@"%@ }",jsonString];
return jsonString;
}
simple star program in c
for(int i=0;i<10;printf("\n",i++))
for(int j=0;j<=10+i;printf("%c",(j++ < 10-i)?' ':'*'));
// another method to get
BOOL var = TRUE;
int n = 3;
for(int i=0;i
{
var = TRUE;
for(int j=0;j<= n+i;j++)
{
if (j >= n-i)
{
if (var == TRUE) {
printf("*");
var = FALSE;
} else {
var = TRUE;
printf(" ");
}
} else {
printf(" ");
}
}
}
Calendar Custom Event Creation in iOS SDK
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"EVENT TITLE";
event.startDate = [[NSDate alloc] init];
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
Note: Please include Eventkit framework and include
#import EventKit/EventKit.h
Friday, July 22, 2011
How to Find Device Width and Height in Android SDK
int screen_width = display.getWidth();
int screen_height = display.getHeight();
Wednesday, July 20, 2011
How to Find Device Width and Height in iOS SDK
NSString *width=[NSString stringWithFormat:@"%g",screenBounds.size.width ];
NSString *height=[NSString stringWithFormat:@"%g",screenBounds.size.height ];
ight %@", width,height,NSStringFromCGRect(screenBounds));
Thursday, July 14, 2011
ASI HTTP Request + JSON Sample
ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:URL];
req.delegate = self;
req.userInfo = [NSDictionary dictionaryWithObject:@"initialRequest" forKey:@"type"];
NSData *body = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
[req appendPostData:body];
[req startSynchronous];
Wednesday, July 13, 2011
Tuesday, July 12, 2011
Monday, July 11, 2011
How To Use UIView Animation Tutorial- iPhone
very easy to understand the animation concept
How To Use UIView Animation Tutorial
Thursday, July 07, 2011
Detect device is an Android Tablet or not
public static int DISPLAY_SCREEN_HEIGHT = 0;
private int MAX_PHONE_WIDTH = 500;
private int MAX_PHONE_HEIGHT = 800;
private boolean isDeviceATablet() {
boolean bIsDeviceATablet = false;
Display display = ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
DISPLAY_SCREEN_WIDTH = display.getWidth();
DISPLAY_SCREEN_HEIGHT = display.getHeight();
if( (DISPLAY_SCREEN_WIDTH > MAX_PHONE_WIDTH) || (DISPLAY_SCREEN_HEIGHT > MAX_PHONE_HEIGHT) )
bIsDeviceATablet = true;
if(bIsDeviceATablet)
Log.i("Device is identified as an Android TABLET.");
else
Log.i("Device is identified as an Android PHONE.");
return bIsDeviceATablet;
}
UITextField delegate Methods in objectice c
Wednesday, July 06, 2011
Tuesday, July 05, 2011
How to Split string into substring in iOS Sdk
NSString *list = @”amal, arun, balaji, dhina, guru, hari, kumar,mahes”;
NSArray *listItems = [list componentsSeparatedByString:@", "];
Monday, July 04, 2011
C # Checkbox Tutorial
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/CheckBox.htm
Thursday, June 30, 2011
Resize UIImage tutorial
{
CGImageRef imgRef = photoimage.CGImage;
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformIdentity;
CGRect bounds = CGRectMake(0, 0, width, height);
bounds.size.width = bounds_width;
bounds.size.height = bounds_height;
CGFloat scaleRatio = bounds.size.width / width;
CGFloat scaleRatioheight = bounds.size.height / height;
transform = CGAffineTransformIdentity;
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextScaleCTM(context, scaleRatio, -scaleRatioheight);
CGContextTranslateCTM(context, 0, -height);
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageCopy;
}
Objective -C Date Formatter Examples - stringFromDate
The format specifiers are quite straightforward, Y = year, M = month, etc. Changing the number of specifiers for a field, changes the output. For example, MMMM generates the full month name “November”, MMM results in “Nov” and MM outputs “11″.
What follows is an example to create the following date string:
Saturday November 8, 2008:
NSDate *today = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"EEEE MMMM d, YYYY"]; NSString *dateString = [dateFormat stringFromDate:today]; [dateFormat release]; |
Here’s another example showing the current time
9:20 AM, PST: NSDate *today = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"h:mm a, zzz"]; NSString *dateString = [dateFormat stringFromDate:today]; [dateFormat release]; |
More details http://iphonedevelopertips.com/cocoa/date-formatters-examples-take-2.html
Simple NSThread Example
Threading
Sample Format:Step .1
Step .2
- (void)myMethod { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
*** code that should be run in the new thread goes here ***
[pool release]; }
Step .3
[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];
Creating the Slider
To create a slider, you allocate it and initialize it with a frame just like any other UIKit control:
slider = [[UISliderControl alloc] initWithFrame: CGRectMake(0.0f, 32.0f, 320.0f, 20.0f)];
Next, you specify its minimum and maximum values with the setMinValue: and setMaxValue: calls. The "setShowValue" call is optional. When set to YES, it displays the current value to the right of the slider (as shown here) so the user gets instant feedback.
[slider setMaxValue:100.0f];
[slider setMinValue:0.0f];
[slider setShowValue:YES];
Now you must add a target for events. Here, I tell the slider to issue the handleSlider: method for mouse dragged events. Fortunately, the iPhone seems to use standard NextStep event equivalents, so 7 corresponds to NSRightMouseDragged, 1 to NSLeftMouseDown and 2 to NSLeftMouseUp. Since the iPhone only supports one button, the right and left gets a little confused.
[slider addTarget:self action:@selector(handleSlider:) forEvents:7];
Next, add the behavior for the message that gets called. In this example, I just write the [slider value] to a text view.
- (void)
handleSlider:(id)sender{
[textView setText:[NSString stringWithFormat:@"End Value: %f", [slider value]]];
}
Reference:
// http://www.tuaw.com/2007/09/04/iphone-coding-using-the-slider/
Difference between NSString and NSMuttableString
// Setup two variables to point to the same string
NSString * str1 = @"Hello World";
NSString * str2 = str1;
// "Replace" the second string
str2 = @"Hello ikilimnik";
// And list their current values
NSLog(@"str1 = %@, str2 = %@", str1, str2);
Mutable strings
// Setup two variables to point to the same string
NSMutableString * str1 = [NSMutableString stringWithString:@"Hello World"];
NSMutableString * str2 = str1;
// "Replace" the second string
[str2 setString:@"Hello ikilimnik"];
// And list their current values
NSLog(@"str1 = %@, str2 = %@", str1, str2);
Notice when you use the immutable NSString class that the only way to "replace" a string is to create a new string and update your variable "str2" to point to it.
This however doesn't affect what "str1" is pointing to, so it will still reference the original string.
In the NSMutableString example, we don't create a second string, but instead alter (mutate) the contents of
the existing "Hello World" string. Since both variables continue to point to the same string object, they will both report the new value in the call to NSLog.
It's important to differentiate between a pointer variable and the actual object it points to.
A NSString object is immutable, but that doesn't stop you from changing the value of a variable which points to a string.
The data type "NSString *" is a pointer to a NSString object, not the object itself.
If you set a break point at either of the NSLog statements within the XCode debugger, you may like to check the raw value of each variable to clarify this.
Reference:
http://www.cocoadev.com/index.pl?NSString
http://stackoverflow.com/questions/1805442/nsstring-immutable-allows-to-change-its-values
Wednesday, June 29, 2011
how to use SwipeGestureRegognizer
swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
action:@selector(swipeMethod:)];
swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeRecognizer];
-(void)swipeMethod: (UISwipeGestureRecognizer *) sender
{
NSLog(@"swipe event detected");
}
// if we need means we use separate swipegesture for left, right, up and down direction
Touch (XY) detection in iPhone
{
startTime = [NSDate timeIntervalSinceReferenceDate];
pt = [[touches anyObject] locationInView:self.view];
NSLog(@"%d,%d x y",pt.x,pt.y);
}
Regarding This Blog
Tuesday, June 28, 2011
To Rotate a view
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.view.transform = CGAffineTransformIdentity;
self.view.transform = CGAffineTransformMakeRotation(180);// angle of rotation
self.view.bounds = CGRectMake(0.0f, 0.0f, 480.0f, 320.0f);
self.view.center = CGPointMake(160.0f, 240.0f);
NSLog(@"end");
[UIView commitAnimations];
Monday, June 27, 2011
Milli Seconds calculation
NSTimeInterval startTime = [NSDate timeIntervalSinceReferenceDate];
// Do something
for(double i=0; i < 1000000; i++ );
// Stop timer
NSTimeInterval endTime = [NSDate timeIntervalSinceReferenceDate];
// Get the elapsed time in milliseconds
NSTimeInterval elapsedTime = (endTime - startTime) * 1000;
// Send it to the Console
NSLog(@"Elapsed time in ms: %f", elapsedTime);
Thursday, June 23, 2011
Memory Management Simple Example
NSString* string1 = [NSString string];
// must release this when done
NSString* string2 = [[NSString alloc] init]; [string2 release];
Network Activity Status Indicator
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
// to stop it, set this to NO
Json Parsing Request
@"some value", @"key1",
@"another value", @"key2",
nil];
NSDictionary *o2 = [NSDictionary dictionaryWithObjectsAndKeys:
@"yet another value", @"key1",
@"some other value", @"key2",
nil];
NSArray *array = [NSArray arrayWithObjects:o1, o2, nil];
NSString *jsonString = [array JSONRepresentation];
NSLog(@"%@",jsonString);
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://sample.com"]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
NSLog(@"%@",connection);
Note:
Before write code you have to include JSON Files. it is available
If you have any doubt ask me...
Thursday, April 21, 2011
iPhone Developer
Create a list in SwiftUI with sticky section headers
Sample Code import SwiftUI struct ContentView : View { @State var isCustomViewControllerDisplayed = false @State private va...
-
Function for getting hardware specific info such as CPU ID, Motherboard Serial Number, Drive Serial Numbers and MAC address . '*...
-
Excel 97 Excel 97-2003 Xls files with ACE OLEDB 12.0 You can use this connection string to use the Office 2007 OLEDB driver (ACE ...
-
Range Operators: Closed Range operators Half-Open Range Operators One-Sided Ranges Closed Range Operators: a...b It defines...