Привет, у меня есть одна кнопка в UIView
. Мое требование - если я нажму эту кнопку UITextField
s отображается в UITableViewCells
. У меня есть идея, как отображать UITextField
s в UIView
, если пользователь нажимает кнопку. Но я не знаю, как отображать UITextField
s внутри UITableViewCell
s, если пользователь нажимает кнопку. Пожалуйста, помогите мне никому.Как отображать UITextFields внутри UITableViewCells в iOS
UIButton *myGreenIconButton1 = [UIButton buttonWithType:UIButtonTypeCustom];
[myGreenIconButton1 addTarget:self action:@selector(GreenIconButtonClicked)forControlEvents:UIControlEventTouchUpInside];
[myGreenIconButton1 setBackgroundImage:[UIImage imageNamed:@"index.jpg"] forState:UIControlStateNormal];
myGreenIconButton1.backgroundColor = [UIColor clearColor];
myGreenIconButton1.frame = CGRectMake(285, 144, 25, 25);
[self.view addSubview:myGreenIconButton1];
-(void)GreenIconButtonClicked
{
UITextField *text1=[[UITextField alloc]initWithFrame:CGRectMake(10, 80, 100, 20)];
text1.borderStyle=UITextBorderStyleRoundedRect;
text1.backgroundColor=[UIColor clearColor];
text1.backgroundColor=[UIColor colorWithRed:0.662745 green:0.662745 blue:0.662745 alpha:0.5];
text1.font=[UIFont systemFontOfSize:14.0];
text1.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
text1.textAlignment=NSTextAlignmentCenter;
text1.delegate=self;
[self.view addSubview:text1];
UITextField *text2=[[UITextField alloc]initWithFrame:CGRectMake(120, 80, 100, 20)];
text2.borderStyle=UITextBorderStyleRoundedRect;
text2.backgroundColor=[UIColor clearColor];
text2.backgroundColor=[UIColor colorWithRed:0.662745 green:0.662745 blue:0.662745 alpha:0.5];
text2.font=[UIFont systemFontOfSize:14.0];
text2.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
text2.textAlignment=NSTextAlignmentCenter;
text2.delegate=self;
[self.view addSubview:text2];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
[cell.textLabel setText:@""];
return cell;
}
Будьте конкретны для того, чего вы хотите достичь. Сначала сделайте все основные понятия понятными. Сначала прочтите UITableView Controller, классы UITableViewCell и их ссылки из apple docs. Удачи. – iShwar