Flipkart Search

Search This Blog

Wednesday, May 13, 2009

http://dblog.com.au/iphone-development-tutorials/iphone-sdk-tutorial-reading-data-from-a-sqlite-database/

http://www.iphonekicks.com/tags/SQLite

http://www.iphonesdkwiki.com/Default.aspx?Page=SDK%20Tutorials&AspxAutoDetectCookieSupport=1

http://www.iphonearch.com/topic/7/sqlite-wrapper/.

http://www.mobileorchard.com/iphone-sqlite-tutorials-and-libraries/

http://www.squidoo.com/sqlitehammer

http://freshmeat.net/articles/sqlite-tutorial

http://leefalin.com/blog/2008/10/02/iphone-sqlite-database-basics/

Tuesday, May 12, 2009

Custom button in UITableViewCell - indexPath



I am currently working on iPhone app number two when I came across a problem that it has taken me a while to sort out. I wanted to place a button inside each UITableCell I am displaying. I then wanted to call a method when the user pressed that button which would perform some action on the information related to the contents of that cell.

For this to be useful I needed to be able to get the indexpath of the row in which the button was pressed. It took me a while to work this out but I eventually came up with a solution which is really simple, in fact so simple I am angry I did not work it out sooner. Below is the line of code I am using in my button method to get the indexPath.


NSIndexPath *indexPath = [self.tblView indexPathForCell:(UITableViewCell *)[sender superview]];

The method signature used was:


- (void)buttonMethod:(UIButton *)sender

From this point on I was then able to access the section and row of the cell in which the button was pressed using:


NSInteger section = indexPath.section;
NSInteger row = indexPath.row;

//for getting cell
UITableViewCell *retcell = (UITableViewCell *)[sender superview];

for deleting cell
switch(indexPath.row){
case 0:
[retcell removeFromSuperview];
break;
case 1:
[retcell removeFromSuperview];
break;
default:
break;

http://blog.beetlebugsoftware.com/post/104154581/face-detection-iphone-source#disqus_thread

http://iphonedevelopertips.com/

http://cocoawithlove.com/

http://www.fieryrobot.com/blog/

http://www.iphoneflow.com/

http://www.insanelymac.com/forum/index.php?showtopic=95195

http://www.71squared.co.uk/2008/12/custom-button-in-uitableviewcell-indexpath/

Friday, May 8, 2009

Displaying a password or text entry prompt on the iPhone


Writing your own iPhone or iPod touch app, and wondering how to create an alert like this? Check out the sample code below.

I needed to display a password prompt in Delivery Status touch and quickly found that there was no ideal way to do it. There are some unsupported methods, but the workaround below—adding a UITextField as a subview of the alert—is the proper method for a third party app, according to Apple.

Aside from the basic technique of adding a UITextField as a subview, there are two other things I struggled with. First, if the text given for the message was too long it would wrap to a second line and appear partially underneath the text field. I worked around this problem by adding my own UILabel subview. The custom label is a single line so you’ll get the standard ellipsis (…) if the text is too long. For the message text I just supply three blank lines, which makes the alert large enough to display the contents. It’s a clunky way to resize the alert, but it works.

The other thing I struggled with was getting the text field to match what Apple uses. The standard beveled edge looks okay, but Apple’s own password prompts have a field that’s customized specifically for alerts. My solution was to insert an image, and display the text field, without a border, on top of it.

Using those tricks, here’s the complete code I’m using to display a password prompt:

UIAlertView *passwordAlert = [[UIAlertView alloc] initWithTitle:@“Server Password” message:@”\n\n\n”
delegate:self cancelButtonTitle:NSLocalizedString(@“Cancel”,nil) otherButtonTitles:NSLocalizedString(@“OK”,nil), nil];

UILabel *passwordLabel = [[UILabel alloc] initWithFrame:CGRectMake(12,40,260,25)];
passwordLabel.font = [UIFont systemFontOfSize:16];
passwordLabel.textColor = [UIColor whiteColor];
passwordLabel.backgroundColor = [UIColor clearColor];
passwordLabel.shadowColor = [UIColor blackColor];
passwordLabel.shadowOffset = CGSizeMake(0,-1);
passwordLabel.textAlignment = UITextAlignmentCenter;
passwordLabel.text = @“Account Name”;
[passwordAlert addSubview:passwordLabel];

UIImageView *passwordImage = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@“passwordfield” ofType:@“png”]]];
passwordImage.frame = CGRectMake(11,79,262,31);
[passwordAlert addSubview:passwordImage];

UITextField *passwordField = [[UITextField alloc] initWithFrame:CGRectMake(16,83,252,25)];
passwordField.font = [UIFont systemFontOfSize:18];
passwordField.backgroundColor = [UIColor whiteColor];
passwordField.secureTextEntry = YES;
passwordField.keyboardAppearance = UIKeyboardAppearanceAlert;
passwordField.delegate = self;
[passwordField becomeFirstResponder];
[passwordAlert addSubview:passwordField];

[passwordAlert setTransform:CGAffineTransformMakeTranslation(0,109)];
[passwordAlert show];
[passwordAlert release];
[passwordField release];
[passwordImage release];
[passwordLabel release];

You can see the result of this code in the screenshot above. It can be customized fairly easily, if you need another type of text entry, more lines of text, or some other change. (Remove the secureTextEntry line or change the keyboardAppearance to customize the text entry field.)

I spent quite a bit of time getting it as pixel-perfect as possible. The only real difference is that it’s a few pixels taller than Apple’s, because of the imprecise way I’m sizing the alert. I think it’s fair to say most people would never notice! I’d love to see a more simplified, official method for creating these alerts, but in the meantime I’m pretty pleased with this solution. If you have any suggestions for improvements, let me know in the comments!


the original post is here

http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html

Saturday, May 2, 2009

Creating a custom Table View Cell programmatically

Ohhk, quite a lot of things done but this one is something which I have used most often. Custom cells can sometimes greatly push ahead the usability of your application. In this post I am going to create a test project which will demonstrate how to create custom cells and use them appropriately to provide better usability. The application will finally look like this:


So to start open xcode and create a new project, chose the template as “Navigation Based” and name it as “CustomCellTestProject”. What template you chose does not matter, refer my previous posts to find how you can start working on any template.
First thing we will do is create a customCell. Right click on Classes and add a new UITableViewCell subclass. Name it as “CustomCell”. Now open CustomCell.h and add the following code:

#import

@interface CustomCell : UITableViewCell {

UILabel *primaryLabel;

UILabel *secondaryLabel;

UIImageView *myImageView;

}

@property(nonatomic,retain)UILabel *primaryLabel;

@property(nonatomic,retain)UILabel *secondaryLabel;

@property(nonatomic,retain)UIImageView *myImageView;

@end


We create the three elements and added them to the contentView of our cell.
synthesize all the three elements in CustomCell.m as we are going to access these elements from other classes.

@synthesize primaryLabel,secondaryLabel,myImageView;


Here we have simply added a primary label to display the primary text, a secondary label and an imageView. These elements will be created and added into the content view of our custom cell. So open CustomCell.m and add the following code

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {

if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {

// Initialization code

primaryLabel = [[UILabel alloc]init];

primaryLabel.textAlignment = UITextAlignmentLeft;

primaryLabel.font = [UIFont systemFontOfSize:14];

secondaryLabel = [[UILabel alloc]init];

secondaryLabel.textAlignment = UITextAlignmentLeft;

secondaryLabel.font = [UIFont systemFontOfSize:8];

myImageView = [[UIImageView alloc]init];

[self.contentView addSubview:primaryLabel];

[self.contentView addSubview:secondaryLabel];

[self.contentView addSubview:myImageView];

}

return self;

}



Now, we have already added the UI elements into our cell but you must have noticed, we have not yet defined how these elements will appear inside cell. Go ahead and add the following code for that:

- (void)layoutSubviews {

[super layoutSubviews];

CGRect contentRect = self.contentView.bounds;

CGFloat boundsX = contentRect.origin.x;

CGRect frame;

frame= CGRectMake(boundsX+10 ,0, 50, 50);

myImageView.frame = frame;

frame= CGRectMake(boundsX+70 ,5, 200, 25);

primaryLabel.frame = frame;

frame= CGRectMake(boundsX+70 ,30, 100, 15);

secondaryLabel.frame = frame;

}


You can do anything in this method to define the lay out of cell. I have simply assigned frames to all the elements.
You can also find a method in CustomCell.m

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

[super setSelected:selected animated:animated];

// Configure the view for the selected state

}

This method can be used to define how your cell should react when it is selected. You can describe what should be the highlight color or may be you want to flash one of the labels anything of your choice. I am leaving this method as it is.
We are done with creating our custom cell and now we have to use it. Open RootViewController.m and import CustomCell.h at the top.


#import “CustomCell.h”

I am going to create 5 cells here, you can just use your own logic of specifying number of cells and data. So change the following method to look like this:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return 5;

}

Now we are going to use our custom cell. If you look at the cellForRow method, you will find that a UItableViewCell has been created and re used. Now all we have to do is to replace this cell with our new cell. Change the code inside this method to look like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @”Cell”;

CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

}

// Set up the cell…

switch (indexPath.row) {

case 0:

cell.primaryLabel.text = @"Meeting on iPhone Development";

cell.secondaryLabel.text = @"Sat 10:30";

cell.myImageView.image = [UIImage imageNamed:@"meeting_color.png"];

break;

case 1:

cell.primaryLabel.text = @"Call With Client";

cell.secondaryLabel.text = @"Planned";

cell.myImageView.image = [UIImage imageNamed:@"call_color.png"];

break;

case 2:

cell.primaryLabel.text = @"Appointment with Joey";

cell.secondaryLabel.text = @"2 Hours";

cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"];

break;

case 3:

cell.primaryLabel.text = @"Call With Client";

cell.secondaryLabel.text = @"Planned";

cell.myImageView.image = [UIImage imageNamed:@"call_color.png"];

break;

case 4:

cell.primaryLabel.text = @"Appointment with Joey";

cell.secondaryLabel.text = @"2 Hours";

cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"];

break;

default:

break;

}

return cell;

}


I have added some dummy data. You can use your data source to provide data for primaryLabel and secondaryLabel. Please note that I have used three images here. You can use any image of your choice. All you need to to do is copy the images and paste it into your project root folder (which in this case is CustomCellTestProject folder). After pasting the files, in xcode right click on Resources (or any group), select Add >> ExistingFiles and then select all the images you want to add in you project. Once added you can simply use them by their names.
Thats it, go ahead and run the project. You will find something wrong when you compare you simulator screen with mine. If you noticed in the CustomCell.m, I have given some frames to the UI elements. You need to make sure that the height of your cell large enough to accomodate all the elements. So add this following code and you fixed the issue:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

return 50;

}


this is not my post the original post is here


http://blog.webscale.co.in/?p=284

Custom UITableViewCell in IB

Creating the project

Create a new project with the “View-based Application” template and call it customTableCell.

Setting up the view controller

Open customTableCellViewController.h and add two IB outlets which we will use to reference to the custom UITableViewCell objects which we will create later. Also, we are going to be using this as a table view delegate and data source so we should state that this class will conform to these protocols. Your customTableCellViewController.h should look like this after editing:

#import 

@interface customTableCellViewController : UIViewController {
IBOutlet UITableViewCell *cellOne;
IBOutlet UITableViewCell *cellTwo;
}

@property (nonatomic, retain) IBOutlet UITableViewCell *cellOne;
@property (nonatomic, retain) IBOutlet UITableViewCell *cellTwo;

@end

Adding the items in Interface Builder

Open customTableCellViewController.xib in IB and drop in a Table View (not a Table View Controller), making it fill the view.

Set the the table view properties to Style -> Grouped.

Link the delegate and dataSource outlets of the table view to “File’s Owner” as illustrated by this screenshot:

ib-tableview-links.png

Add two Table View Cell items in IB to your customTableCellViewController.xib file. Then, open each table view cell item and drop something different onto each one of them so you will tell them apart.

Now we need to link these table view cells to the IB outlets we created earlier. To do this, right click on “File’s Owner” and link cellOne and cellTwo outlets to the table view cells you have just created. You should then have something which looks like this:

ib-cell-links.png

Save and close customTableCellViewController.xib.

Controller Code

Open customTableViewController.m

We will need to implement three functions, namely tableView:cellForRowAtIndexPath:, numberOfSectionsInTableView: and tableView:numberOfRowsInSection: which are the usual data source protocol functions which we need to implement. The three functions are outlined below.

tableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if([indexPath row] == 0) return cellOne;
if([indexPath row] == 1) return cellTwo;
return nil;
}

numberOfSectionsInTableView:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

tableView:numberOfRowsInSection:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}

These functions tell the table view to display 1 section, with 2 cells and when the table view asks for each cell, the custom UITableViewCell objects are returned.

And that’s it!

If you now build and run the application then you will notice that your custom cells are being shown - brilliant! Now you can do something fun with the custom cells! For instance you could put a text box or a slider in it and then bind actions of it to a function in your view controller to act upon the user’s input.

Go play!

http://ericasadun.com/

http://steaps.techaos.com/2009/03/01/tutorial-scrolling-an-object-into-view/

http://www.ipodtouchfans.com/forums/archive/index.php/t-102782.html
http://twilloapp.blogspot.com/
http://blog.mcilvena.com/2009/01/xcode-starting-point-for-iphone-hand-coders/
http://vimeo.com/3363949
http://iphonedevelopertips.com/xcode/real-men-dont-use-interface-builder.html

http://www.ipodtouchfans.com/forums/archive/index.php/f-55.html
http://forums.macrumors.com/archive/index.php/f-135-p-6.html
http://blogs.remobjects.com/blogs/mh/2009/04/11/p271
http://www.ipodtouchfans.com/forums/archive/index.php?t-58898.html
http://www.servin.com/iphone/NSObject.html
http://weblog.bignerdranch.com/?p=56
http://www.insanelymac.com/forum/index.php?showtopic=96104&st=40

http://ihatetheiphonesdk.blogspot.com/2008/04/reason-2-interface-builder-is-buggy-and.html

http://kwigbo.com/wp/2009/02/27/custom-uitableviewcell-in-interface-builder/

http://iphone.galloway.me.uk/iphone-sdktutorials/custom-uitableviewcell/

http://iphone.zcentric.com/2008/08/05/custom-uitableviewcell/

Friday, May 1, 2009

// This will get a random number between 0 and 9
int ranX = arc4random() % 10;

Cocos2d Rectangle Rectangle Collision Detection

- (BOOL) rect:(CGRect) rect collisionWithRect:(CGRect) rectTwo
{
float rect_x1 = rect.origin.x;
float rect_x2 = rect_x1+rect.size.width;

float rect_y1 = rect.origin.y;
float rect_y2 = rect_y1+rect.size.height;

float rect2_x1 = rectTwo.origin.x;
float rect2_x2 = rect2_x1+rectTwo.size.width;

float rect2_y1 = rectTwo.origin.y;
float rect2_y2 = rect2_y1+rectTwo.size.height;

if((rect_x2 > rect2_x1 && rect_x1 < rect2_x2) &&(rect_y2 > rect2_y1 && rect_y1 < rect2_y2))
return YES;

return NO;
}

iPhone SDK Show Activity Indicator in the Status Bar

[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;


iPhone SDK dismiss the keyboard

Q: How do you remove the keyboard when the Return/Done button is pressed?
A: Set the delegate on the text field that will bring up the keyboard. Add the following selector to the object that you set to be the delegate.

- (BOOL) textFieldShouldReturn:(UITextField *) textField
{
[textField resignFirstResponder];

return YES;
}

iPhone SDK Load Text File Into NSString

NSString *path = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"]; 
NSString *fileText = [NSString stringWithContentsOfFile:path];


Create UIButton/button with images

UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);

[playButton setTitle:@"Play" forState:UIControlStateNormal];

playButton.backgroundColor = [UIColor clearColor];

[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];

UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];

UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];

[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];

UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];

UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];

[playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];

[playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:playButton];

Splash Screen

Show splash screen during loading

//In AppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application {

m_viewController = [[SplashViewController alloc] initWithNibName:nil bundle:nil];

[window addSubview:m_viewController.view];

[window makeKeyAndVisible];

//set delay before showing new screen

[NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(onSlashScreenExpired:) userInfo:nil repeats:NO];

}

- (void)onSlashScreenExpired:(id)userInfo{

[m_viewController.view removeFromSuperview];

[window addSubview:[navigationController view]];

[window makeKeyAndVisible];

}