Loading

Monday, January 24, 2011

Build Multiple Projects From One Code

1--> Suppose your main project is MainProject.xcodeproj, The very first step is open project in Xcode and add a new target (TargetProj)



2--> edit MainProject info from Target

3--> change TargetProj-Info.plist in Info.plist File Property

4--> and change targetProj in Product Name

Tuesday, January 4, 2011

Create Object of class to use as a View

in ChildClass.h
@interface
{
UINavigationController *ng;
id parentController;
}
@property(nonatomic, retain) id ParentController;
@property (nonatomic, retain) IBOutlet UINavigationController *ng;

in ChildClass.m

@synthesize ParentController = parentController;
@synthesize ng;


in ParentClss.m

ChildClass* childObject = [[ChildClass alloc]initWithNibName:@"ChildView" bundle:[NSBundle mainBundle]];
childObject.ParentController=self;
childObject.ng = self.navigationController;
[childObject.view setFrame:CGRectMake(Frame)];
[YourView addSubview:childObject.view];
[self.view sendSubviewToBack:YourView];

Monday, January 3, 2011

UIKeyboardTypeNumberPad missing "return" key

I get the code from Google and modify it for DONE Button in UIKeyboardTypeNumberPad (works in iPhone 4 SDK)

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if(textField==txtZipCode)
{
[self setViewMovedUp:YES];
[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(keyboardDidShowOrHide:)
name: UIKeyboardDidShowNotification object:nil];

}
else
{

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
}



}
- (void) keyboardDidShowOrHide : (id) sender {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 427, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setBackgroundImage:[UIImage imageNamed:@"doneup.png"] forState:UIControlStateNormal];
[doneButton setBackgroundImage:[UIImage imageNamed:@"donedown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
[tempWindow addSubview:doneButton];


}
-(void)doneButton:(id)sender
{
UIButton *btntmp=sender;
[btntmp removeFromSuperview];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
[self setViewMovedUp:NO];
[txtZipCode resignFirstResponder];
}

Wednesday, December 29, 2010

Store imge from URL to app bundle

NSString *StrUrl=[[NSString alloc] initWithFormat:@"%@",yourURLstring];
NSData *_PicData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:StrUrl] ];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath =[NSString stringWithFormat:@"%@/%@",[paths objectAtIndex:0],YourPhotoName.Ext];
[_PicData writeToFile:documentsPath atomically:YES];

Tuesday, October 19, 2010

Table Scroll to Top

if([result count]>0)
{
NSIndexPath* indPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tblArticle scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}

Use of Autorelase Pool

The First line of Thread =

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];


and the Last Line is

[pool release];

Tuesday, October 12, 2010

Hide ActivityIndicator When Page DidFinish Loading

1. [WebViewWebDetail loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@""]]];

NSString* WebAddress=[NSString stringWithFormat:@"%@",YourWebAddress];
NSURL* url=[NSURL URLWithString:[WebAddress stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[WebViewWebDetail loadRequest:[NSURLRequest requestWithURL:url]];


2. WEBVIEW Delegate Methods

- (void)webViewDidStartLoad:(UIWebView *)webView
{
Process.alpha=1.0;
Process.hidesWhenStopped = YES;
[Process startAnimating];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
if([Process isAnimating])
[Process stopAnimating];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{

if([Process isAnimating])
[Process stopAnimating];
/*
if (error != NULL) {
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle: [error localizedDescription]
message: [error localizedFailureReason]
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}*/
}