2011-04-29 130 views
0

我仍然在爲我的iphone應用程序註冊頁面而苦苦掙扎 - 此刻我遇到了與性別相關的問題。將表視圖作爲輸入視圖?

我的想法是,當用戶按下性別字段時,包含「男性」和「女性」的表格視圖從底部向上滑動,然後用戶在他的實際性別旁邊勾選複選標記。我真的不明白如何正確地獲得這個性別表視圖。

目前我有我的GenderTableViewCell它指向一個用戶交互啓用標籤和GenderTableViewController,然後我已經將第一個輸入視圖設置爲後者的表視圖。通過這種方式,當「性別」字段被觸摸時,具有「男性」和「女性」的表格實際上會滑動,但由於表格不是按照我指定它位於GenderTableViewController.xib中的分組風格,所以我感覺我不是在正確的軌道上!!

我一直在谷歌搜索和谷歌搜索,但一直沒能找到任何類似的例子 - 也許這不是很好,有一個表視圖滑動?我應該使用UIPicker嗎?

回答

1

我會使用UIPicker代替。實現起來要容易得多,對用戶來說這是一個更加標準化的體驗。

+0

嗯,好的 - 我會這樣做,而不是:)然後:)謝謝! – Stine 2011-04-29 22:00:05

+0

恐怕我覺得使用picker視圖並不容易。我沒有看到我的性別表格單元格中有兩個性別的選擇器是如何填充的? – Stine 2011-04-29 23:02:56

+0

您需要一個類來實現[UIPickerViewDataSource](http://developer.apple.com/library/ios/#documentation/iPhone/Reference/UIPickerViewDataSource_Protocol/Reference/Reference.html)協議和[UIPickerViewDelegate](http: //developer.apple.com/library/ios/#documentation/uikit/reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html)協議。如果你願意,你可以讓你的視圖控制器實現它們,因爲它是一個簡單的選擇器。有一個簡單的教程[這裏](http://www.iphonesdkarticles.com/2009/01/uipickerview-creating-simple-picker.html)。 – thefugal 2011-04-29 23:39:05

1
-(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]; 
     [email protected]"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; 
     [email protected]"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;   
} 
+0

謝謝你回答!我不知道這是如何幫助我做我的性別選擇器?:} – Stine 2011-04-30 11:23:44

+0

只需使用它與一個UISegementControl – Andrew 2011-04-30 14:45:10