Добавление uitableview в выпуски uitableviewcells? - PullRequest
5 голосов
/ 01 сентября 2011

enter image description here У меня есть одно приложение для iphone, в которое я добавляю uitableview в uitableviewcell.in, что каждая uitablecell содержит табличное представление, которое имеет динамическую строку, основанную на элементе entry.i.e пользователя. tableview в первой ячейке содержит 3 rows.tableview в секундах row содержит 4 row.thus он варьируется. Моя проблема в том, что когда я прокручиваю tableview, то записи повторяются. Как я могу решить это - любой учебник или пример кода?

 -(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)
    {

        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;

    }




}

Я хочу создать экран, подобный показанному на изображении. Там, где каждая белая секция имеет разный размер. Ее длина динамична, как в записи пользователя. Так есть ли лучший подход, чем добавление uitableview внутри ячейки uitableview?

1 Ответ

2 голосов
/ 02 сентября 2011

Я решил проблему, используя

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

вместо static NSString *CellIdentifier=@"CellIdentifier"; в первом просмотре таблицы, но я знаю, что это сделает uitableview медленно прокручивающимся, как и повторное использование CellIdentifier.дал бы лучшее решение или лучший способ сделать uitableview вложенным, я был бы признателен.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...