简体   繁体   English

如何创建像iPhone Facebook应用程序一样的登录屏幕?

[英]how can you create a login screen like the iPhone facebook app?

The Facebook app for the iPhone has a great username/password setup where it almost looks like it is a uitableview with UITextField's inside the two rows, is this how it is done? iPhone的Facebook应用程序有一个很好的用户名/密码设置,它几乎看起来像UITextField在两行内的uitableview,这是怎么做的? Or would it be something different to this altogether? 或者这完全不同于它?

If it is a tableview, how can I access the textfields inside the tableview once the user hits the Login button? 如果是tableview,一旦用户点击Login按钮,如何访问tableview内的文本字段? Is there a quick way to iterate over the cells in a tableview? 有没有快速的方法来迭代tableview中的单元格?

A simple one, I know, but I didnt want to implement an elaborate tableview if I didnt need to... 一个简单的,我知道,但如果我不需要,我不想实现精心设计的tableview ...

The source : https://github.com/c99koder/lastfm-iphone 来源https//github.com/c99koder/lastfm-iphone

Edited: It's possible you customize the UITableViewCell and put a UITextField inside. 编辑:您可以自定义UITableViewCell并在其中放置U​​ITextField。 However, there is an even easy way to achieve this, since the login / signup page would almost always be static. 但是,有一种更简单的方法可以实现这一点,因为登录/注册页面几乎总是静态的。 See below. 见下文。

LastFM for iPhone used a similar login / signup page design. LastFM for iPhone使用了类似的登录/注册页面设计。 And they open-sourced their code. 他们开源了他们的代码。 Take a look at the nib file and you will know how LastFM did this. 看看nib文件,你就会知道LastFM是如何做到这一点的。 :-) :-)

  • Screenshot 1: original 截图1:原创
  • Screenshot 2: after I removed some of the background png files. 屏幕截图2:我删除了一些后台png文件。

在此输入图像描述在此输入图像描述

Create a tableview controller and go to the xib file -> attributes inspector->tableview and select "group styled" instead of plain. 创建一个tableview控制器并转到xib文件 - > attributes inspector-> tableview并选择“group styled”而不是plain。 Then u can customize the tableview cells in the code by adding the textfields for username and password. 然后,您可以通过添加用户名和密码的文本字段来自定义代码中的tableview单元格。 Then create a new UIView and set the view to the tableview's footer view for the login button. 然后创建一个新的UIView并将视图设置为tableview的页脚视图以获取登录按钮。

For more explanation regarding the same, go through the answer for this question. 有关相同的更多解释,请查看此问题的答案。

Table view in iPhone in grouped style 在分组样式的iPhone中的表视图

It looks like it's not using a UITableView at all (otherwise, you'd be able to scroll the page up and down). 它看起来根本就没有使用UITableView (否则,你可以上下滚动页面)。 It's just two UITextField s over custom backgrounds (or with custom backgrounds). 它只是两个UITextField不是自定义背景(或自定义背景)。

Now, if you wanted to use a UITableView , what you could do is store as variables the UITextField s within the UITableViewCell s. 现在,如果您想使用UITableView ,您可以做的是将UITextField存储为UITableViewCell的变量。 Then, when the person clicks a login button, you just get the text value from the UITextField s. 然后,当用户单击登录按钮时,您只需从UITextField获取text值。

But, again, if you wanted to emulate the Facebook look, you don't need to bother with the UITableView . 但是,再次,如果你想模仿Facebook的外观,你不需要打扰UITableView

Hope this helps! 希望这可以帮助!

Alright, now that I understand your question (thanks @Jonathan!), yes it does look like it is a tableview using custom UITableViewCells with a UITextField. 好了,既然我理解了你的问题(感谢@Jonathan!),是的,它确实看起来像是一个使用UITextField的自定义UITableViewCells的tableview。

After creating the custom cell with a UITextField you can assign your view controller as the UITextField delegate and access the values at various points through the delegate methods: 使用UITextField创建自定义单元格后,您可以将视图控制器指定为UITextField委托,并通过委托方法访问各个点的值:

– textFieldShouldBeginEditing:
– textFieldDidBeginEditing:
– textFieldShouldEndEditing:
– textFieldDidEndEditing:

As an example, in your textFieldShouldReturn: , you can grab a reference to the indexPath of that cell with : 例如,在textFieldShouldReturn: ,您可以使用以下命令获取对该单元格的indexPath的引用:

NSIndexPath *indexPath = [self.loginTable indexPathForCell:(MemberLoginCell*)[[textField superview] superview]];

And then to the cell with: 然后到细胞:

MemberLoginCell *cell = (MemberLoginCell*)[self.loginTable cellForRowAtIndexPath:indexPath];

Or simply grab the textField.text value and assign it to an NSString that can be passed to your LOGIN method as required. 或者只需获取textField.text值并将其分配给NSString,该NSString可以根据需要传递给您的LOGIN方法。

I know there's already an accepted answer, but I created a facebook-type login page, using a UITableView. 我知道已有一个已接受的答案,但我使用UITableView创建了一个facebook类型的登录页面。 The code is here on github 该代码是在这里在github

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM