Iphone 是否将表视图作为输入视图?

Iphone 是否将表视图作为输入视图?,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我还在为我的iphone应用程序的注册页面苦苦挣扎——目前我在性别领域遇到了问题 我的想法是,当用户按下性别字段时,一个包含“男”和“女”的表格视图从底部向上滑动,然后用户在其实际性别旁边打勾。我真的不明白如何正确地获取这个性别表视图 目前,我有一个GenderTableViewCell,它指向一个支持用户交互的标签和一个GenderTableViewController,然后我将第一个的输入视图设置为后者的表视图。这样,当触摸性别字段时,带有“男性”和“女性”的表格实际上会向上滑动,但由于表格

我还在为我的iphone应用程序的注册页面苦苦挣扎——目前我在性别领域遇到了问题

我的想法是,当用户按下性别字段时,一个包含“男”和“女”的表格视图从底部向上滑动,然后用户在其实际性别旁边打勾。我真的不明白如何正确地获取这个性别表视图

目前,我有一个GenderTableViewCell,它指向一个支持用户交互的标签和一个GenderTableViewController,然后我将第一个的输入视图设置为后者的表视图。这样,当触摸性别字段时,带有“男性”和“女性”的表格实际上会向上滑动,但由于表格不是我指定的分组样式,因此它位于GenderTableViewController.xib中,我感觉我没有走上正确的轨道


我一直在谷歌搜索,但没有找到任何类似的例子-也许它是不好的,有一个表视图向上滑动?我应该改用UIPicker吗?

我会改用UIPicker。这将更容易实现,而且对用户来说,这是一种更标准的体验。

Hmm,好吧-我会这样做:)谢谢!恐怕我不觉得使用选择器视图更容易。我不知道如何从我的性别表单元格中用两种性别填充选择器?您需要一个类来实现协议和协议。如果需要,您可能可以让视图控制器实现这两个功能,因为它是一个简单的选择器。这里有一个简单的教程。非常感谢你对这篇文章的评论。我目前拥有的唯一控制器是一个表视图控制器,它控制用户名、生日、性别、手机号码和密码表单元格,其中每个单元格都是UITableViewCell的某个子类的实例。如果我现在将整个表视图控制器作为数据源(例如,自定义性别表视图单元格中的性别选择器),我会觉得有点奇怪?您根本不需要将表视图控制器作为数据源并委托选择器。如果愿意,您当然可以创建自己的类来实现这些协议(如果您愿意,您甚至可以更进一步,创建一个数据源对象和一个委托对象)。这样做更干净,从代码分离的角度来看也更好。谢谢您的回答!我不确定这对我做性别选择有什么帮助?:}只需将其与UISegementControl一起使用即可
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    [tableView setBackgroundColor:[UIColor clearColor]];

    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    return 2;
}

-(NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section

{

    return 1;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

       return 35;

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexpath // set row value for table

{


   UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"anycell"];  
   if(cell == nil)
   {
    cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"anycell"] autorelease];
/// UIImageView *imgView=[[[UIImageView alloc] init] autorelease];
//  UIImage *img;
    CGRect frame;
    frame.origin.x=10;
    frame.origin.y=5;
    frame.size.width=280;

     if(indexpath.section ==0)
    {
        //img=[UIImage imageNamed:@"textbox1.png"];
        frame.size.height=27;
        txtname=[[UITextField alloc] initWithFrame:frame];
        txtname.delegate=self;
        txtname.textColor=[UIColor colorWithRed:211.0/255 green:236.0/255.0 blue:245.0/255.0 alpha:1.0];
        txtname.placeholder=@"User Name";
        [txtname setAutocorrectionType:UITextAutocorrectionTypeNo];
        [txtname setKeyboardType:UIKeyboardTypeURL];
        [cell.contentView addSubview:txtname];
    }
    else if(indexpath.section == 1)
    {
        frame.size.height=27;
        txtpassword=[[UITextField alloc] initWithFrame:frame];
        txtpassword.delegate=self;
        txtpassword.textColor=[UIColor colorWithRed:211.0/255 green:236.0/255.0 blue:245.0/255.0 alpha:1.0];
        txtpassword.secureTextEntry=TRUE;
        txtpassword.placeholder=@"Password";
        [cell.contentView addSubview:txtpassword];
    }
    else
    {
        frame.size.height=27;
        //frame.size.width=200;
        btnSave=[[UIButton alloc] initWithFrame:frame];
        [btnSave setImage:[UIImage imageNamed:@"user-save.png"] forState:UIControlStateNormal];
        [btnSave addTarget:self action:@selector(saveClicked) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:btnSave];

    }
}
if(indexpath.section == 0)
    txtname.text=appDelegate.setObj.username;
else if(indexpath.section == 1)
    txtpassword.text=appDelegate.setObj.password;

UIImageView *imgView=[[[UIImageView alloc] init] autorelease];
imgView.image=[UIImage imageNamed:@"textbox1.png"];
cell.backgroundView =imgView;

cell.selectionStyle=UITableViewCellSelectionStyleNone;
return cell;        
}