我在UITableView上方有一个UITextField。当我选择UITextField时,UITableView会反复拉伸。这是我的onViewLoad代码:

- (void)viewDidLoad
{
 [super viewDidLoad];
 self.title = @"Clock In Time";

     CALayer *layer= pickUpWeighCapacityList.layer;
 UIColor* uic = UIColorFromRGB(0x336600);
 CGColorRef* cgf = uic.CGColor;

  layer.borderWidth = 2;
  layer.borderColor = cgf;
  layer.cornerRadius = 10;
  layer.frame = CGRectMake(20.0f, 33.0f, 280.0f, 178.0f);

  pickUpWeighCapacityList.dataSource = self;
  pickUpWeighCapacityList.delegate = self;
  pickUpWeighCapacityList.tableHeaderView = nil;
  pickUpWeighCapacityList.tableFooterView = nil;

  pickUpWeighCapacityList.frame = CGRectMake(20.0f, 33.0f, 280.0f, 178.0f);

  i = 0;

  signOutTimeField.placeholder = @"Time to Clock Out of Work";
  picker = [[UIDatePicker alloc] init];
  signOutTimeField.inputView = picker;

  UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
        style:UIBarButtonSystemItemDone target:self action:@selector(doneEditing)];
  self.navigationItem.rightBarButtonItem = rightButton;
  [rightButton release];
  [picker release];
}

这是我具有视图功能的代码:
 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
  // Return the number of sections.
  return 1;
}


 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // Return the number of rows in the section.
  return 3;
}

如何获得不拉伸的UITableView? (iOS 4.3。XCode 3.2.6-不要判断我)。

最佳答案

解决方案不是显而易见的。在viewDidLoad部分中,放置以下行:

 [[NSNotificationCenter defaultCenter] addObserver:self
    selector:@selector(keyboardWillHide:)
             name:UIKeyboardWillHideNotification object:nil];

然后在viewController中包含以下代码:
 - (void)keyboardWillHide:(NSNotification *)note
    {
     [pickUpWeighCapacityList setFrame:
          CGRectMake(original-x-coord,original-y-coord,
                     original-length,original-width)];
    }

10-01 05:35
查看更多