Pages

Showing posts with label Iphone. Show all posts
Showing posts with label Iphone. Show all posts

Saturday, November 5, 2011

How to attach database with other database in SQLite

To Attach DB with another DB, i use below code................


Create first database:
[self createEditableCopyOfDatabaseIfNeeded];
Create second database:
[self createEditableCopyOfDatabaseIfNeeded_New];

Attach Database second with first:
[self AttachDB];
use of both data base in single SQL:
[self inserttblData];

-(voidAttachDB
{
               BOOL success;
               NSFileManager *fileManager=[[NSFileManager defaultManager]autorelease];
               NSArray *paths= NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);        
               success = [fileManager fileExistsAtPath:[[paths objectAtIndex:0] stringByAppendingPathComponent:@"database2.sqlite3"]];
               if(success)
               {
                        NSString *sql = [NSString stringWithFormat:@"ATTACH DATABASE \"%@\" AS newdb",[[paths objectAtIndex:0] stringByAppendingPathComponent:@"database2.sqlite3"]];
                        // here database is an sqlite object and which refer database1
                        int intReturnValue = sqlite3_exec(database, [sql UTF8String], NULL, NULL, NULL);       
                        if(intReturnValue == 1)
                         {
                                    NSAssert1(0, @"Error: failed to attach database with message '%s'.", sqlite3_errmsg(database));
                        }
                        else
                        {
                                    NSLog(@"Done");  
                        }
               }   
}

-(int)inserttblData
{
               int i=0;
               @try
               {
                       
                        sqlite3_stmt *statement=nil;
                        NSString  *sql=nil;  
                        sql=[NSString stringWithFormat:@"INSERT INTO testtable1 SELECT * FROM newdb.testtable2"];
                        if(sqlite3_prepare_v2(database, [sql UTF8String], -1, &statement, NULL)!=SQLITE_OK)
                        {
                                    NSAssert1(0, @"Error: failed to insertstatement with message '%s'.", sqlite3_errmsg(database));
                        }                                  
                        int success=sqlite3_step(statement);
                        if (success == SQLITE_ERROR)
                        {
                                    NSAssert1(0, @"Error: failed to insert into the database with message '%s'.", sqlite3_errmsg(database));
                        }
                        sqlite3_finalize(statement);
                       
                        return i;
                       
                       
               }
               @catch (NSException *e)
               {
                        return 0;
               }
               return i;
}

If you got any new way and get problem, write here.......

Thx,




Sunday, April 17, 2011

iphone: Remember always small thing second


  • 1.     Compare Null value that come from net.
  • 2.     Image load from web.
  • 3.     Navigate view from bottom.
  • 4.     To dismiss this view.
  • 5.  Get UDID of Apple Device.
  • 6.     TAB base Application to come tab page instance of last visited page.
  • 7.     Make Back Button on New Page rather with Back Name.
  • 8.     Able Cancel button of ActionSheet on tab bar.
  • 9.     Get Array from NSString.
  • 10. How to make Shadow on UiLable. 
  • 11. How to make image Corner round. 



Compare Null value that come from net:

if([[[data objectForKey:@"pic"] description] isEqualToString:@""])

or

if([data objectForKey:@"pic"] != [NSNull null])

Image load from web:

 NSData *receivedData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:URL]];
 UIImage  *image  = [[UIImage alloc] initWithData:receivedData] ;

Navigate view from bottom:
[self presentModalViewController:ObjChatting animated:YES];


To dismiss this view:
if(self.navigationController == nil)
          [self dismissModalViewControllerAnimated:YES];

Get UDID of Apple Device:
NSString *udid = [[UIDevice currentDevice] uniqueIdentifier];

NOTE: we can get other detail from UIDevice class.

TAB base Application to come tab page instance of last visited page:

- (void)viewDidDisappear:(BOOL)animated
{          
    if(self.navigationController.visibleViewController==self)
    {
      [self.navigationController popToViewController: [self.navigationController.viewControllers objectAtIndex:0] animated:YES];
    }      
}

Make Back Button on New Page rather with Back Name:
 UIBarButtonItem  *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStyleBordered target: nil action: nil];
 [[self navigationItem] setBackBarButtonItem: newBackButton];
[newBackButton release];

 NOTE: Use in viewDidLoad in first page from where you write push statement.

Able Cancel button of ActionSheet on tab bar:

[actionSheet showInView:self.tabBarController.view];

NOTE: use when cancel button come over tabbar. (In this situation, cancel button will not work)

Get Array from NSString:

NSArray *arr = [str componentsSeparatedByString:@"\n"];

where str is @"One \n two \n three"

NOTE: Avoid to use NSMutableString, i had problem


How to make Shadow on UiLable:
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
or
lblname.shadowColor = [UIColor whiteColor];
with
lblname.shadowOffset = CGSizeMake(0.0, 1.0);

How to make image Corner round. 
For Button:
btnbottom4.imageView.layer.cornerRadius=15.0;
btnbottom4.imageView.layer.borderWidth=0.0;
btnbottom4.imageView.layer.borderColor=[[UIColor clearColor] CGColor];
For ImageView:
imageView.layer.cornerRadius=15.0; imageView.layer.borderWidth=0.0; imageView.layer.borderColor=[[UIColor clearColor] CGColor];













Saturday, April 2, 2011

iphone: Remember always small thing

  1. Enable Keyboard return button for Textfield
  2. Enable Keyboard return button for SearchBar
  3. Deselect the UITableCell
  4. open safari from Application
  5. Convert NSData to NSString.
  6. Convert NSString to NSData
  7. Change UIAlertView Button Color
  8. To scroll the view at time of Editing textfield and keyboard appear.
  9. Get the Index path of table Row by UITextfield (UItextField in Table View).





Enable Keyboard return button for Textfield:
this button call following fuction default:
- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
  [textField resignFirstResponder]; 
   return YES; 

}
Enable Keyboard return button for SearchBar:
this button call following fuction default:

- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
searchBar.showsCancelButton = NO;
}


Deselect the UITableCell:
By Default, when we select the table cell it Become Blue so we can avoid it by

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)  newIndexPath 
{ 
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES]; 
}

open safari from Application:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"Enter URL Here"]];

Convert NSData to NSString:

NSString *str = [[NSString alloc] initWithData:aData encoding:NSASCIIStringEncoding];

Convert NSString to NSData:
NSData *data = [aStr dataUsingEncoding: NSASCIIStringEncoding];


Change UIAlertView Button Color:

Create the object of UIAlertView , the call automatically following method:
- (void)willPresentAlertView:(UIAlertView *)alertView 
[[[alertView subviews] objectAtIndex:1] setBackgroundColor:[UIColor redColor]];
    /*
      Here index 0 = Title , 1 = cancel Button , 2,3.... = otherButton
*/

To scroll the view at time of Editing textfield and keyboard appear: 
just set the frame of view in textFieldDidBeginEditing such as:
     self.view.frame=CGRectMake(0,-30, 320, 460);
and again set the view in textFieldDidEndEditing as:
    self.view.frame=CGRectMake(0,0, 320, 460);




Get the Index path of table Row by table field such as in  textFieldDidBeginEditing method:

    When we use text field in UITableView.

- (void) textFieldDidBeginEditing:(UITextField *)textField 
{
UITableViewCell *cell = (UITableViewCell*) [[textField superview] superview];
NSIndexPath *path = [mytable indexPathForCell:cell]; 

    // use this path as indexpath of table fuction

}

Saturday, August 14, 2010

Iphone: How To Create Global AppDel Objec

How To Create Global AppDel Object.

Actually, When we working on Iphone Application Most of time we need to create AppDelegate Object to access the functions or Variables.
So instead of creating each time a new object of AppDel,we can create only single time and use directly to any view of Application.
we can do this as follows:

1) Define Obj in .pch file such as

YourAppDelegate *AppDel;

2) Alloc Memory to Obj in AppDel Class in applicationDidFinishLaunching:(UIApplication *)application function
such as AppDel = (YourAppDelegate *) [[UIApplication sharedApplication] delegate];

Sunday, April 11, 2010

Iphone: Taking Screen Short Programmatically

hi.........

In this Blog, i want to Explain about taking Screen short of iphone programmatically.

its so simple and require only few lines of code.
that capture the screen short and save it the iphone photo library.


Step 1.

Make a iphone application.
Step 2.

Insert that code in viewDidLoad method of your viewController.h

CGRect screenRect = [[UIScreen mainScreen] bounds];
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext(); [[UIColor blackColor] set]; CGContextFillRect(ctx, screenRect);
[self.view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(newImage, nil, nil, nil);
UIGraphicsEndImageContext();



that work fine and you can check by checking iphone photo library.

Sunday, April 4, 2010

Iphone : Hello World First Application.

Here i Use only Simple Code to Define the Application and not use so much Detail to confuse u.
so just use it and execute the application.

In .h File of Hello world,
first we declared A UIButton Object and then Connect them with Interface Builder.

.h file As

IBOutlet UIButton *msg;

@property (retain,nonatomic) UIButton *msg;

- (IBAction) displayMsg:(id)sender;



.m file.......


Here We define the DisplayMsg function on touch inside up event and here we use UIAlertView Class to show the HelloWorld Msg.


- (IBAction)displayMsg:(id)sender
{
s_msg.text = @"";
UIAlertView *str =[[UIAlertView alloc] initWithTitle:@"Alert MSG" message:@"HELLO WORLD" delegate:self cancelButtonTitle: @"NO" otherButtonTitles:@"YES",nil];
str.delegate = self ;
[str show];
[str release];

}

Now we have to define Delegate method of UIAlertView such as:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
// NO = 0, YES = 1
if(buttonIndex == 0)
s_msg.text = @"NO";
else {
s_msg.text = @"YES";
}


use it to build your first application on Iphone.

And Post Comment on it and if u have any Problem.


thanks