Showing posts with label TableView Other Method. Show all posts
Showing posts with label TableView Other Method. Show all posts

Tuesday, December 15, 2015

UITableView Extra Methods for iOS


Select TableView Row Programmatically(Swipe Menu)

+(void)settingTableViewRowSelected:(UITableView *)myTableView selectedRow:(NSInteger)row{

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
    [myTableView selectRowAtIndexPath:indexPath animated:YESscrollPosition:UITableViewScrollPositionNone];

    //[myTableView.delegate tableView:APP_DELEGATE.menuVC.tableView didSelectRowAtIndexPath:indexPath];

}

Other TableView Method


#pragma mark - TableView Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return array.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[array  objectAtIndex:section]  count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return @"title";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return 100;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //put your values, this is part of my code
    UIView *view = [[UIView allocinitWithFrame:CGRectMake(00,self.view.bounds.size.width40.0f)];
    [view setBackgroundColor:[UIColor colorWithRed:(0.0/255.0green:(140.0/255.0blue:(204.0/255.0alpha:1.0]];
    UILabel *lbl = [[UILabel allocinitWithFrame:CGRectMake(03,self.view.bounds.size.width20)];
    //lbl.frame = view.frame;
    lbl.textAlignment = NSTextAlignmentCenter;
    [lbl setFont:[UIFont fontWithName:AppFONT size:15.0]];
    [lbl setTextColor:[UIColor whiteColor]];
    [view addSubview:lbl];
    
    [lbl setText:@"title";
    
    return view;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
    
}