开发者

Adding uitableview inside uitableviewcells issues?

开发者 https://www.devze.com 2023-04-01 22:04 出处:网络
I have one iphone application in which i am adding uitableview inside uitableviewcell.in that each uitablecell contains tableview which has dynamic row based upon user\'s entry.i.e. tableview in first

Adding uitableview inside uitableviewcells issues?

I have one iphone application in which i am adding uitableview inside uitableviewcell.in that each uitablecell contains tableview which has dynamic row based upon user's entry.i.e. tableview in first cell contains 3 rows.tableview in seconds row contains 4 row.thus it varies.my problem is that when i scroll the tableview then entries are repeated.how can i solve that?any tutorial or sample code?

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
{


    if(tableView==self.tbView)
    {
        UITableView *tb;

    static NSString *CellIdentifier=@"CellIdentifier";

    UITableViewCell *cell1=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        int height;

    if(cell1==nil)
    {

  开发者_如何学JAVA      cell1=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
        tb=[[[UITableView alloc] initWithFrame:cell1.contentView.frame style:UITableViewStylePlain]autorelease];
        tb.rowHeight=50;
        [cell1.contentView addSubview:tb];

            NSMutableArray *a2=[[NSMutableArray alloc]init];
                a2=[dateArray objectAtIndex:indexPath.row];

        cntt=cntt+1;
            int no=[a2 count]+1;
            height=(no*50);
            heightcnt2=heightcnt2+1;
        NSLog(@"frame of tableviewcontentcell is %@",cell1.contentView.frame);
        tb.frame=CGRectMake(cell1.contentView.frame.origin.x,cell1.contentView.frame.origin.y,cell1.contentView.frame.size.width,height);
        tb.delegate=self;
        tb.dataSource=self;
        tb.tag=tag1;
        tb.scrollEnabled=NO;
        tag1=tag1+1;

    }

        return cell1;


    }   
    else 
    {
        static NSString *CellIdentifier2 = @"Cell";


         CategoryListCustomCell *cell = (CategoryListCustomCell *)[[tableView dequeueReusableCellWithIdentifier:CellIdentifier2]autorelease];
        if (cell == nil) {
            cell = [[[CategoryListCustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier2]autorelease];
        }



        if(indexPath.row==0)
        {
            NSMutableArray *temp=[[NSMutableArray alloc]init];
            int cmp=[dateArray count];
            if(cnt<=cmp-1)
            {
                temp=[dateArray objectAtIndex:cnt];
                transationObj=[temp objectAtIndex:0];
            }
            NSDate *date=transationObj.tran_date;
            NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
            [dateformatter setDateStyle:NSDateFormatterFullStyle];
            NSString *strDate=[dateformatter stringFromDate:date];
            cell.lblcatname.text=strDate;
            cnt=cnt+1;

        }

        else 
        {
            transationObj=[[Transaction alloc]init];
            NSMutableArray *temp2=[[NSMutableArray alloc]init];
            int cmp2=[dateArray count];
            if(cnt2<cmp2-1)
            {
                temp2=[dateArray objectAtIndex:cnt2];
                for(int i=0;i<[temp2 count];i++)
                {
                    transationObj=[temp2 objectAtIndex:i];
                    cell.lblcatname.text=transationObj.tran_des;

                }



            }
            cnt2=cnt2+1;


        }

        cell.backgroundColor=[UIColor grayColor];
               return cell;

    }




}

I want to create screen like shown in image.where each white section is not same size.its lengh is dynamic as per users entry.so is there any better approach then adding uitableview inside uitableview cell?


I have solved the issue by using

NSString *CellIdentifier=[NSString stringWithFormat="CellIdentifier%d",indexPath.row];

instead of static NSString *CellIdentifier=@"CellIdentifier"; in first tableview but i know that this will make uitableview to scroll slowly as it is nor reusing CellIdentifier.so it any one can give better solution or better way to make uitableview nested i would appreciate it.

0

精彩评论

暂无评论...
验证码 换一张
取 消