2013-08-01 71 views
-1

我有一個屏幕,圖片和標籤在頂部和中間的某個地方,我想添加兩個文本框。我非常喜歡Facebook登錄屏幕的樣子,我想要做類似的事情,但這對我來說並不容易,作爲一個絕對的初學者。如何在Facebook登錄屏幕中創建一組文本字段?

我正在使用Storyboard和當前屏幕的視圖控制器實現UIViewController。

我想了解如何管理它,所以,任何提示是apreaciated。

謝謝。

LE:這是我試過的,但沒有結果: 我在屏幕上添加了一個表格視圖,並且我爲兩個文本字段創建了屬性,所以我可以動態地在兩個單元格中添加兩個文本字段。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 2; 
} 
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"]; 
    if(cell == nil) 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 

    if (indexPath.row == 0) { 
     self.txtUsername = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 20)]; 
     self.txtUsername .placeholder = @"Username"; 
     self.txtUsername .autocorrectionType = UITextAutocorrectionTypeNo; 
     [self.txtUsername setClearButtonMode:UITextFieldViewModeWhileEditing]; 
     cell.accessoryView = self.txtUsername ; 
    } 
    if (indexPath.row == 1) { 
     self.txtPassword = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 280, 20)]; 
     self.txtPassword.placeholder = @"Password"; 
     self.txtPassword.secureTextEntry = YES; 
     self.txtPassword.autocorrectionType = UITextAutocorrectionTypeNo; 
     [self.txtPassword setClearButtonMode:UITextFieldViewModeWhileEditing]; 
     cell.accessoryView = self.txtPassword; 
    } 


    [cell addSubview:self.txtUsername]; 
    [cell addSubview:self.txtPassword]; 

    cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    return cell; 
} 
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 

    return 1; 
} 
我不使用靜態細胞

,所以我理解了它的唯一方法就是以編程方式添加這些文本字段。

我應該用戶靜態單元格嗎?

+0

你能上傳圖片嗎? –

回答

2

你打算做什麼可以通過tableView輕鬆實現,只需在單元格內插入文本字段即可。爲了更好地理解它們的工作原理,請在表格視圖上提供此文檔以更好地理解它們的工作方式:Apple's Documentation on Table View Programming

如果您正在使用描述中所述的故事板,那麼您將希望刪除視圖控制器中的委託方法您發佈的代碼)的表視圖,該應用程序不會這樣工作。

聽起來像你試圖實現可以用靜態單元來完成,因此你不應該使用數據源方法。

+0

所以,你是以編程方式或使用最初發布的故事板?因爲如果您正在故事板中設置視圖,則更新後的問題描述將不起作用。 – vzm

+0

我不使用靜態單元格,從我讀過的內容中他們只使用UITableViewController。在故事板中,我只添加了一個帶有2行的表格視圖,並且在控制器中我編程式地添加了文本字段 – user2611691

+0

是的,你是正確的,靜態單元格只能與UITableViewController一起工作,因此我建議你使用它來達到你的預期目的不僅是實現你所尋找的結果的更好方式,它還將更好地看起來/功能。 – vzm