Tuesday, 31 December 2013

GridView in iOS.

As you guys have collection view , you can use it as grid.
Then you think what I have made to use for?

So, I am presenting advantage of my GridView below:--

1)First of all it is compatible with ios 5.0 + , on the other hand , UICollectionView doen't work in iOS 5.0.
2)It automatically adjust cell blocks according to string size and extend width of the grid.
3)It allows you to define cell type as if you want to give input or keep it as simple label.
4)Also allows to perform calculation like
    Add,
    Multiply
    Subtract
    Devide
    and Mod Operation on cell.
5)Row click action returns row data in the format of NSDictionary.
6)Support landscape as well as portrait mode.
7)Made for both iPhone and iPad.




1) First of all you need to download library I have put on the shared link

Download GridViewLib Here

2) After you have downloaded it,Import both "include" and "libGridViewTable.a" to your project and check copy to folder option while adding.After importing it would look like image below.
  


3)Don't forget to add some framework:
     i)QuartzCore Framework
     ii)CoreGraphics Framework


4) Go to Project->Build Setting -> Search Header Path
    and set path to $SOURCE_ROOT/include
    and "Always Search User Paths" to YES as shown below



5) Now you have successfully added the library , you can use it by just importing "GridViewTable.h" file and use its DataSource and Delegate Methods.

Here is demo how I have used in header and Implementation File.





Monday, 30 December 2013

How to add methods to existing protocol?

Sometimes we need to enable touchBegans on UITableView instead of didSelect method but
we are not able to do it.

So here we make a custom protocols methods to invoke touchesBegan and touchesEnded methods using Category files.

Follow the steps to do so:-

1)Within your project , Go to File Menu ->File -> New and click.
2)It will show dialog having two segments that is IOS and OS X . Withing IOS , select Cocoa Touch.
3)After that , click on "Objective-C category" option and go next.



4)It'll display another dialog having two options with Input Fields that is "Category" and "Category On".
5)Give TouchGesture as Category and select UITableView in Category On option and go next and click create button.
6)It will create two Files named UITableView+TouchGesture.h and UITableView+TouchGesture.m



Now  we have created category files successfully, and further we will work on custom protocols to UITableView delegate.

In header File , create a protocol named MyCustomDelegate subclass of UITableViewDelegate and write two methods within it like given below:-

@protocol MyCustomDelegate <UITableViewDelegate>
-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event;
-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event;
@end


and Within Interface write a method to invoke custom delegate like

- (id<MyCustomDelegate>) customDelegate;

Now your header file would look like




In Implementation File , define interface method and call delegates on touchBegan and touchEnded gesture methods as given in the file.



At last we made it , now you can use it by importing UITableView+TouchGesture.h file in the place wherever you want to use this new delegate method that will invoke on the touchBegan and touchEnded of tableView.But keep in mind by implementing these methods didSelect method will not work.

write this tableView protocol in your viewController and perform your task within it.

-(void)tableView:(UITableView *)tableView touchBegan:(NSSet*)touches withEvent:(UIEvent *)event
{
  //do your stuff.
}

-(void)tableView:(UITableView *)tableView touchEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
 //do your stuff.
}