私はシミュレータ上で私のアプリケーションを動かすまではうまくいきました。すべてのビューの方向を含む。さて、私がIpadでアプリケーションをテストしたとき、私は私が世話をしなければならないと思う問題に気付きました。
私は、UILabel、UITextView、およびUButtonをそれぞれの行に持つUITableViewを持っています。私が直面している問題は、テキストビューに何かを入力すると、向きを変えていくうちに、テキストがキーボードとともに消えてしまうことです。私がオリエンテーションを変更するたびに行うテーブルビューの再読み込みである理由は分かっていますが、それを処理することはできません。テーブルビューの再読み込みは、他のビューが適切な向きになるためにも重要です。
何をする必要がありますか?コードが必要な場合は、質問を更新します。Ipadの向きの問題 - UITextViewのリロードとキーボードが消える
Nitish
更新:
- (void)viewDidLoad
{
[super viewDidLoad];
checkTextView = FALSE;
[email protected]"Tasks";
arrTextViews = [[NSMutableArray alloc]init];
[self checkOrientation];
// Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void) checkOrientation
{
UIInterfaceOrientation orientation = self.interfaceOrientation;
@try
{
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
textXX=340.0;
btnXX=900.0;
textLL=480.0;
[commentsTable reloadData];
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
textXX=240.0;
btnXX=650.0;
textLL=350.0;
[commentsTable reloadData];
}
}
@catch (NSException *ex) {
[Utils LogExceptionOnServer:@"TodayViewController" methodName:@"checkOrientation" exception:[ex description]];
}
}
- (void)receivedRotate:(NSNotification *)notification
{
[self checkOrientation];
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrComments count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
// Configure the cell
NSArray *arrSeparate = [strName componentsSeparatedByString:@":"];
NSString *str1 = [arrSeparate objectAtIndex:0];
NSString *str2 = [arrSeparate objectAtIndex:1];
lblName1=[[UILabel alloc]init];
lblName1.frame=CGRectMake(10, 13, 200, 30);
lblName1.numberOfLines=1;
[lblName1 setText:str1];
[lblName1 setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[lblName1 setFont:[UIFont boldSystemFontOfSize:25.0]];
[lblName1 setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblName1];
[lblName1 release];
lblName2=[[UILabel alloc]init];
lblName2.frame=CGRectMake(10, 50, 200.0, 70);
lblName2.numberOfLines=2;
[lblName2 setText:str2];
[lblName2 setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[lblName2 setFont:[UIFont boldSystemFontOfSize:25.0]];
[lblName2 setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblName2];
[lblName2 release];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(textXX-1, 12, textLL+2, 132)];
imgView.image = [UIImage imageNamed:@"box.png"];
[cell.contentView addSubview:imgView];
[imgView release];
//txtComment
txtComment = [[UITextView alloc] initWithFrame:CGRectMake(textXX,13, textLL, 130)];
txtComment.scrollEnabled = YES;
txtComment.userInteractionEnabled = YES;
txtComment.tag=indexPath.row;
iTextViewTag = txtComment.tag;
strGetText = txtComment.text;
[txtComment setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[txtComment setFont:[ UIFont boldSystemFontOfSize: 25 ]];
[cell.contentView addSubview:txtComment];
[arrTextViews addObject:txtComment];
[txtComment release];
UIImageView *imgBtn = [[UIImageView alloc] initWithFrame:CGRectMake(btnXX-1, 12, 72, 132)];
imgBtn.image = [UIImage imageNamed:@"commentbbtnbox.png"];
[cell.contentView addSubview:imgBtn];
[imgBtn release];
//btnClose
btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
btnClose.frame=CGRectMake(btnXX, 13,70,130);
btnClose.tag= indexPath.row;
btnClose.backgroundColor = [UIColor grayColor];
[btnClose addTarget:self action:@selector(btnCloseAction:) forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:btnClose];
return cell;
}
textviewのテキストはどこで入手できますか?テーブルビュー内または一部のデリゲートメソッド内またはviewDidLoad内ですか? – Nitish
willAnimateRotationToInterfaceOrientationは、TableViewを管理するViewControllerでオーバーライドできるUIViewControllerメッセージです。回転の直前に呼び出されるはずです。テキストを保存するために必要なコードを追加する必要があります。より多くのヘルプが必要な場合は、いくつかのコード(tableViewのコンテンツ:cellForRowAtIndexPath:とviewDidLoad)を入力してください。 – FKDev
私は自分の質問を更新しました。 – Nitish