2013-10-28 2 views
1

Я пытаюсь показать список комментариев, используя subview. Я добавил subview в self.view, и я добавил tableview к нему, чтобы показать список комментариев. теперь я хочу включить пользователя для добавления комментариев, я попытался добавить еще один подзаголовок в первый с текстовым полем и кнопкой, но отображаемое представление и текстовое поле и кнопка не работают. это код, который я использую для этого:добавить subView в другой SubView ios

GRect screenRect = [[UIScreen mainScreen] bounds]; 
CGFloat screenWidth = screenRect.size.width; 
CGFloat screenHeight = screenRect.size.height; 

// notification button 
myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight)]; 
[myView setBackgroundColor:[UIColor whiteColor]]; 

commentView = [[UIView alloc] initWithFrame:CGRectMake(0,screenHeight-70,screenWidth,70)]; 
[commentView setBackgroundColor:[UIColor redColor]]; 

table = [[UITableView alloc] initWithFrame:CGRectMake(0,50, screenWidth, screenHeight-100)];; 
table.dataSource=self; 
table.delegate=self; 

UILabel *currentdate = [[UILabel alloc] initWithFrame:CGRectMake(0,10,screenWidth-40,50)]; 
currentdate.backgroundColor = [UIColor clearColor]; 
[currentdate setTextColor: [UIColor blueColor]]; 
[currentdate setText:@"Comments"]; 
currentdate.textAlignment= UITextAlignmentCenter; 
currentdate.font = [UIFont fontWithName:@"Helvetica" size:20.0]; 

commentFeild = [[UITextField alloc] initWithFrame:CGRectMake(50,screenHeight-50,screenWidth-50,50)]; 
[email protected]"add comment"; 
commentFeild.backgroundColor = [UIColor whiteColor]; 
[commentFeild setTextColor: [UIColor blueColor]]; 
commentFeild.textAlignment= UITextAlignmentRight; 
commentFeild.font = [UIFont fontWithName:@"Helvetica" size:15.0]; 
[commentFeild.layer setCornerRadius:14.0f]; 
[commentFeild setTag:2030]; 
//[commentFeild setDelegate:self]; 

UIButton *doneBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
doneBtn.frame = CGRectMake(screenWidth-45, 10,40, 30); 
doneBtn.backgroundColor = [ UIColor clearColor]; 
[doneBtn setTitle:@"Done" forState:UIControlStateNormal]; 
[doneBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 
[doneBtn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside]; 

UIButton *add=[UIButton buttonWithType:UIButtonTypeRoundedRect]; 
add.frame = CGRectMake(0,screenHeight-50,40,50); 
add.backgroundColor = [ UIColor clearColor]; 
[add setTitle:@"add" forState:UIControlStateNormal]; 
[add setTitleColor:[UIColor blueColor] forState:UIControlStateNormal]; 
[add addTarget:self action:@selector(addComment) forControlEvents:UIControlEventTouchUpInside]; 

if(![taskObject.status isEqualToString:@"doneTask"]) 
{ 
    [commentView addSubview:commentFeild]; 
    [commentView addSubview:add]; 
} 

[myView addSubview:doneBtn]; 
[myView addSubview:currentdate]; 
[myView addSubview:table]; 
[myView addSubview:commentView]; 

[self.view addSubview:myView]; 

ответ

0

Каркас commentField вызывает проблему, поскольку значение у очень большой комментарий текстовое поле не отображается в commentview

Правильно кадр, и он будет отображаться

commentFeild = [[UITextField alloc] initWithFrame:CGRectMake(50,0,screenWidth-50,50)]; 

примечание: frame вид зависит только от его родительского представления, а не над родителями. В вашем случае commentField's кадр зависит от размеров комментариев и не имеет никакого отношения к какому-либо другому супервизу.

+0

да, это так. – etab

+0

Знаете ли вы, как перемещать commentView Up, когда клавиатура появляется, чтобы написать комментарий, а затем вернуться после отправки комментария? – etab

+0

Refer (This) [https://developer.apple.com/library/ios/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html] –

1

Вы добавляете комментарийFeild в commentView.

commentView = [[UIView alloc] initWithFrame:CGRectMake(0,screenHeight-70,screenWidth,70)]; 

Высота commentView составляет 70 и у позиции commentField является ScreenHeight-50 это у положения до велика как по сравнению с высотой commentView.

x и y положение детского просмотра вычисляется от родителей x и y.

Смежные вопросы