Thursday, September 30, 2010

How to expand cell of a Table View with animation... :)

here is how i am managing this

1. you need an NSMutableArray

the NSMutablearray is the same count as the datasource array for the table

so, you need to populate it with something like this

Code:

self.cellAccessArray = [[NSMutableArray alloc] initWithObjects:@"closed",@"closed",@"closed",@"closed",nil];
[self.cellAccessArray release];

this means we have 4 table rows

now, in your heightForRowAtIndexPath, put this

Code:

if([[self.cellAccessArray object atIndex:indexPath.row] isEqualToString:@"open"])
{
return 140;
}
return 70;

now, to the didSelectRowAtIndexPath

put this


Code:

if([[self.cellAccessArray objectAtIndex:indexPath.row] isEqualToString:@"closed"])
{
[self.cellAccesArray replaceObjectAtIndex:indexPath.row withObject:@"open"];
}
else
{
[self.cellAccesArray replaceObjectAtIndex:indexPath.row withObject:@"closed"];
}

[tableView reloadRowsAtIndexPath:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];


If you want a more Attractive way to do this then click here.

Friday, September 24, 2010

Methods for CUT, COPY n PASTE in any iPhone App.

-(IBAction)cut {
  [self copy];
  textPad.text = @"";
} 
 
-(IBAction)copy {

        NSString *copyString = [[NSString alloc] initWithFormat:@"%@",[textPad text]];
        UIPasteboard *pb = [UIPasteboard generalPasteboard];
        [pb setString:copyString];
}

-(IBAction)paste {
        UIPasteboard *pb = [UIPasteboard generalPasteboard];
        textPad.text = [pb string];
} 

Monday, September 20, 2010

My Camera

This is an App which is useful when u need to develop a Camera App which provides the facility to user to edit image size and crop using a Square Box. To get Source Code click here.

My Compaas

This is an iPhone App which describe the working of Compass in 3gs n upgraded iphones. to download the Source Code click here.

Friday, September 3, 2010

How to create own delegates..... (Protocol methods)

if u want to update any variable or call any method of any class for Eg. Class A). of your project while the control is working in any other class(for Eg. Class B), then you can do it by creating your own delegate/protocol in calling class, and Declare that method in that protocol n define that method in called class.... to elaborate lets see the code.....


Calling.h //First Class

@protocol myDelegate [NSObject]
@optional
- (void) doIt;
@end

@interface Calling :
UIViewController {

id [
myDelegate] delegate;
}

@property(nonatomic, retain) id
[myDelegate] delegate;

@end




Calling.m

#import " Calling.h"

#import " Called.h "

@implementation Calling

@synthesize delegate;

- (void)viewDidLoad {
[super viewDidLoad];

[delegate hideUnhideMenu];
}

@end




Called.h // Class B

@interface Called : UIViewController
[myDelegate] {

}

@end




Called.m

#import " Called.h"

@implementation Called

- (void)viewDidLoad {
[super viewDidLoad];

Calling* obj = [[Calling alloc] init];
obj.delegate = self;
}

- (void)hideUnhideMenu {

//Do your updation here.
}

@end


NOTE: please replace "[" type of brackets with "<". 



for more details about this post click here

Delegate methods to delete rows from a table view.

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
// Updates the appearance of the Edit|Done button as necessary.

[super setEditing:editing animated:animated];
[tblName setEditing:editing animated:animated];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Do whatever data deletion you need to do...
// Delete the row from the data source
//[arrItems removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:YES];
}
[tableView endUpdates];
}

Add Discloserbutton in tableview n do sumthing on click

- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UIButtonTypeDetailDisclosure;
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
//Do what you want here.
}