我在iPad應用程序中使用一個表格和一個UIview。我想在第二個視圖中顯示table的選定行索引中的不同選項。應用程序用戶界面附加在這裏。我的代碼片段是這樣的: -如何在iPad中顯示和隱藏所選表格行索引的視圖?
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row=indexPath.row;
UILabel *lblName, *lblUserName, *lblOldPassword, *lblCreditCardDetails, *lblNewPassword;
UITextField *txtName, *txtUserName, *txtOldPassword, *txtNewPassword, *txtCreditCardDetails;
UIButton *btnsaveprofile, *btnSavePassword, *btnSaveCreditCardDetails;
UIView *subView =[[UIView alloc] initWithFrame:CGRectMake(321, 0, 448, 980)];
[viewDetail addSubview:subView];
if (row==0) {
[subView removeFromSuperview];
UIView *subView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 448, 980)];
[viewDetail addSubview:subView];
lblName =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 40)];
[email protected]"Name";
[lblName setBackgroundColor:[UIColor clearColor]];
[subView addSubview:lblName];
[lblName release];
txtName =[[UITextField alloc] initWithFrame:CGRectMake(141, 0, 200, 40)];
txtName.borderStyle=UITextBorderStyleRoundedRect;
[subView addSubview:txtName];
lblUserName =[[UILabel alloc] initWithFrame:CGRectMake(0, 60, 140, 40)];
[email protected]"User Name";
[lblUserName setBackgroundColor:[UIColor clearColor]];
[subView addSubview:lblUserName];
[lblUserName release];
txtUserName =[[UITextField alloc] initWithFrame:CGRectMake(141, 60, 200, 40)];
txtUserName.borderStyle=UITextBorderStyleRoundedRect;
[subView addSubview:txtUserName];
btnsaveprofile =[[UIButton alloc] initWithFrame:CGRectMake(100, 160, 100, 40)];
[btnsaveprofile setTitle:@"Save" forState:UIControlStateNormal];
[btnsaveprofile addTarget:self action:@selector(btnSaveProfile) forControlEvents:UIControlEventTouchUpInside];
[subView addSubview:btnsaveprofile];
}
if (row==1) {
[subView removeFromSuperview];
UIView *subView1 =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 448, 980)];
[viewDetail addSubview:subView1];
lblOldPassword =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 140, 40)];
[email protected]"Old Password";
[lblOldPassword setBackgroundColor:[UIColor clearColor]];
[subView1 addSubview:lblOldPassword];
txtOldPassword =[[UITextField alloc] initWithFrame:CGRectMake(141, 0, 200, 40)];
txtOldPassword.secureTextEntry=YES;
txtOldPassword.borderStyle=UITextBorderStyleRoundedRect;
[subView1 addSubview:txtOldPassword];
lblNewPassword =[[UILabel alloc] initWithFrame:CGRectMake(0, 60, 140, 40)];
[email protected]"New Password";
[lblNewPassword setBackgroundColor:[UIColor clearColor]];
[subView1 addSubview:lblNewPassword];
txtNewPassword =[[UITextField alloc] initWithFrame:CGRectMake(141, 60, 200, 40)];
txtNewPassword.secureTextEntry=YES;
txtNewPassword.borderStyle=UITextBorderStyleRoundedRect;
[subView1 addSubview:txtNewPassword];
btnSavePassword =[[UIButton alloc] initWithFrame:CGRectMake(100, 160, 100, 40)];
[btnSavePassword setTitle:@"Save" forState:UIControlStateNormal];
[btnSavePassword addTarget:self action:@selector(btnNavigationBarClicked) forControlEvents:UIControlEventTouchUpInside];
[btnSavePassword setBackgroundImage:[UIImage imageNamed:@"btn_signin_bg.png"] forState:UIControlStateNormal];
[subView1 addSubview:btnSavePassword];
}
if (row==2) {
[subView removeFromSuperview];
UIView *subView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 448, 980)];
[viewDetail addSubview:subView];
lblCreditCardDetails =[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 180, 40)];
[email protected]"Credit Card Details";
[lblCreditCardDetails setBackgroundColor:[UIColor clearColor]];
[subView addSubview:lblCreditCardDetails];
[lblCreditCardDetails release];
txtCreditCardDetails =[[UITextField alloc] initWithFrame:CGRectMake(181, 0, 200, 40)];
txtCreditCardDetails.secureTextEntry=YES;
txtCreditCardDetails.borderStyle=UITextBorderStyleRoundedRect;
[subView addSubview:txtCreditCardDetails];
[txtCreditCardDetails release];
btnSaveCreditCardDetails =[[UIButton alloc] initWithFrame:CGRectMake(100, 130, 100, 40)];
[btnSaveCreditCardDetails setTitle:@"Save" forState:UIControlStateNormal];
[btnSaveCreditCardDetails setBackgroundImage:[UIImage imageNamed:@"btn_signin_bg.png"] forState:UIControlStateNormal];
[btnSaveCreditCardDetails addTarget:self action:@selector(btnSaveCreditCard) forControlEvents:UIControlEventTouchUpInside];
[subView addSubview:btnSaveCreditCardDetails];
[btnSaveCreditCardDetails release];
btnSaveCreditCardDetails.hidden=YES;
}
}
我用這個代碼,但不幸的是它與以前的觀點重疊。
我的問題是如何避免重疊或以什麼方式隱藏以前的意見。
只是使用普通視圖和didselectrow使用快速enumaration像(UIview *在viewDetail中查看){[view removeFromSuperView];}然後添加你自定義標籤文本到viewDetail – krishh 2013-05-02 09:35:08