Wednesday 18 December 2013

UITableView Data Add,Update and Delete from table advance level using extra feature like scrolling in iphone

Table.h

#import <UIKit/UIKit.h>



@interface ip15ViewController : UIViewController <UITableViewDataSource,
                                                    UITableViewDelegate>
{
    BOOL keyboardVisible;
}

@property (nonatomic, retain) IBOutlet UITableView *formTblView;

@property (nonatomic, retain) IBOutlet UIView   *topView,
                                                *bottomView;

@property (nonatomic, retain) IBOutlet UITableViewCell *cell0,
                                                        *cell1,
                                                        *cell2,
                                                        *cell3;

@property (nonatomic, retain) IBOutlet UITextField  *nameTxtFld,
                                                    *ageTxtFld,
                                                    *emailTxtFld,
                                                    *passwordTxtFld;

@property (nonatomic, retain) IBOutlet UIToolbar *txtFldsBar;

- (IBAction)donekeyboardBtnPressed:(id)sender;

@end

Table.m

@synthesize formTblView,
            topView,
            bottomView,
            cell0,
            cell1,
            cell2,
            cell3;

@synthesize nameTxtFld,
            ageTxtFld,
            emailTxtFld,
            passwordTxtFld,
            txtFldsBar;


- (IBAction)donekeyboardBtnPressed:(id)sender
{
    [nameTxtFld resignFirstResponder];
    [ageTxtFld resignFirstResponder];
    [emailTxtFld resignFirstResponder];
    [passwordTxtFld resignFirstResponder];
}

- (void)keyboardDidShow: (NSNotification *)notif
{
            if(keyboardVisible)
                        return;

    keyboardVisible = YES;
   
    formTblView.frame = CGRectMake(0, 0, 320, 300);
    formTblView.contentSize = CGSizeMake(320, 460);
            [formTblView setContentOffset:CGPointMake(0, 100) animated:YES];
   
}

- (void)keyboardDidHide: (NSNotification *)notif
{
            if(!keyboardVisible)
        return;
   
    keyboardVisible = NO;

    formTblView.frame = CGRectMake(0, 0, 320, 460);
    formTblView.contentSize = CGSizeMake(320, 460);
            [formTblView setContentOffset:CGPointMake(0, 0) animated:YES];
}


- (void)viewDidLoad
{
    [super viewDidLoad];
   
    nameTxtFld.inputAccessoryView = txtFldsBar;
    ageTxtFld.inputAccessoryView = txtFldsBar;
    emailTxtFld.inputAccessoryView = txtFldsBar;
    passwordTxtFld.inputAccessoryView = txtFldsBar;
   
   
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidShow:)
                                                 name:UIKeyboardDidShowNotification
                                               object:nil];
           
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidHide:)
                                                 name:UIKeyboardDidHideNotification
                                               object:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ((indexPath.row == 0) ?
            cell0.frame.size.height : (indexPath.row == 1) ?
                cell1.frame.size.height : ((indexPath.row == 2) ?
                        cell2.frame.size.height : cell3.frame.size.height));
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return topView.frame.size.height;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return topView;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return bottomView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return bottomView.frame.size.height;
}


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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return ((indexPath.row == 0) ?
            cell0 : (indexPath.row == 1) ?
                cell1 : ((indexPath.row == 2) ?
                         cell2 : cell3));
}

No comments:

Post a Comment

Comment