我自定义了一个tableview,在每个cell里面添加一个textField,当点击textField弹出键盘的时候我想把tableview向上移动,并且改变table的大小,使它不会被键盘覆盖,现在问题是当我改变table的大小的时候,tableview的数据显示出了问题,比如本来是在第二行的数据显示到了最后一行,下面是我的代码,请大家帮忙看看是什么问题。-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
cell.lineBreakMode = UILineBreakModeTailTruncation;
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(20, 6, 180, 32)];
textfield.font = [UIFont fontWithName:@"Arial" size:14.0f];
textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[textfield addTarget:self action:@selector(edit:) forControlEvents:UIControlEventEditingDidBegin]; [cell addSubview:textfield];
[textfield release];
}
return cell;
}
-(void) edit: (UIControl *)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[self.table setContentOffset:CGPointMake(0,200) animated:YES];
[self.table setFrame:CGRectMake(0,0,320,200)];
[UIView commitAnimations];
}
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
cell.lineBreakMode = UILineBreakModeTailTruncation;
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(20, 6, 180, 32)];
textfield.font = [UIFont fontWithName:@"Arial" size:14.0f];
textfield.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[textfield addTarget:self action:@selector(edit:) forControlEvents:UIControlEventEditingDidBegin]; [cell addSubview:textfield];
[textfield release];
}
return cell;
}
-(void) edit: (UIControl *)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
[self.table setContentOffset:CGPointMake(0,200) animated:YES];
[self.table setFrame:CGRectMake(0,0,320,200)];
[UIView commitAnimations];
}
解决方案 »
- 想学iphone开发 求一本比较好的OBJect-c语言书
- 怎么release子视图?
- 关于webview的缓存
- Objective-C语言对象与实例,是否相同?
- 怎么用电脑登录苹果手机里面的APP
- 求共享cocos2d-iphone-3.1.0.zip安装包
- 求助:禁用已下载app里个别功能
- 大神谁能解释下UICollectionView的两种注册cell方式的不同??
- ios如何实现把其他的framwork和.a的静态库打进我们自己项目的framework中,求指导
- svn问题 求前辈指导下
- UIScrollview的setContentOffse
- 打算做一些基于iphone的应用软件,没有Mac电脑
[cell.contentView addSubview:textfield];
而不是
[cell addSubview:textfield];