tableView convertPoint: fromView: odd behaviour and workaround

前端 未结 2 604
时光说笑
时光说笑 2021-01-15 02:52

I have a tableView with custom cells. One of the objects in the cell is a textField. The tableViewController is the textFieldDelegate. The datasource for the table is an arr

2条回答
  •  梦谈多话
    2021-01-15 03:40

        - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
        {
    
                NSString *text = [array_loaddata objectAtIndex:indexPath.row] ;
                UIFont *font = [UIFont systemFontOfSize:10];
                CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping];
    
                int count = size.height + 0;
    
                return count;
    
        }
    
    
        - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
        {
            return 1;
        }
    
        - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
        {
            return [array_loaddata count];
        }
    
        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            NSString *CellIdentifier =[NSString stringWithFormat:@"Cell%d",indexPath.row] ;
    
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    
                NSString *text = [array_loaddata objectAtIndex:indexPath.row] ;
                UIFont *font = [UIFont systemFontOfSize:10];
                CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping];
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(46, 0, size.width, size.height)];
                label.numberOfLines = 0;
                label.textColor = [UIColor grayColor];
                label.lineBreakMode = NSLineBreakByWordWrapping;
                label.text = (text ? text : @"");
                label.font = font;
                label.backgroundColor = [UIColor clearColor];
                [cell.contentView addSubview:label];
                [label release];
    
    
            }
            return cell;
        }
        - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
    link==http://mobile.tutsplus.com/tutorials/iphone/iphone-json-twitter-api/
            /*
        NSString *appurl =[NSString stringWithFormat:@"xx"];
        appurl = [appurl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
        NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:appurl]];
        NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse: nil error: nil ];
        NSString  *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
    */
    
        }
    

提交回复
热议问题