Thursday, May 22, 2014

Manage Two Tableview in ios Xcode

On click UITableview cell Effect other UITableview cell

Example. when one click on 6th row of one tableview cell move cell of Second tableview to 60th row.

It like   1 -> 10,2 -> 20,3 -> 30 etc.

Now continue with code.

1. Take two Tableview side by side on viewController.

2. Initialize it.



3. Set Delegate and Datasource to fileOwner.

 4. on select row set scroll position of second tableview to particular cell.


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==self.tblTen)
        return 10;
    else if(tableView==self.tblTenList)
        return 100;
   
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellStr=@"clsten";
    ClsTen *cellTen=(ClsTen *)[tableView dequeueReusableCellWithIdentifier:cellStr];
                     if(cellTen==nil)
                     {
                         NSArray *nib=nil;
                          nib=[[NSBundle mainBundle] loadNibNamed:@"clsTen" owner:self options:nil];
                         cellTen=[nib objectAtIndex:0];
                         cellTen.backgroundColor=[UIColor clearColor];
                       
                     }
 
    cellTen.lblNo.text=[NSString stringWithFormat:@"%ld",indexPath.row];
    return cellTen;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView==self.tblTen)
   [[self tblTenList] scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row * 10 inSection:0]  atScrollPosition:UITableViewScrollPositionTop animated:YES];
    if(tableView==self.tblTenList)
    {
        TenSubList *tenSubList=nil;
        tenSubList=[[TenSubList alloc] initWithNibName:@"TenSubList_iPhone" bundle:nil];
       
        [self.navigationController pushViewController:tenSubList animated:YES];
    }
}








Result























When Click on 3rd cell, second cell move to 30


No comments:

Post a Comment