如何验证用户并在成功时加载表视图?

时间:2022-10-30 09:28:15

i'm new to iphone dev.. i was trying to create an application which will authenticate the user and download some data from de url(.php) via xml parsing into the table view. i have figured how to parse and populate the table view but stuck up with user authentication... ie- extracting textfield data and appending it to the URL on submit. n loading table view on success... could anyone please help me out..

我是iphone开发新手。我试图创建一个应用程序,该应用程序将对用户进行身份验证,并通过xml解析从de url(.php)下载一些数据到表视图。我已经知道如何解析和填充表视图,但仍然坚持用户身份验证……提取文本字段数据并将其添加到提交的URL。加载表视图成功…谁能帮帮我吗?

2 个解决方案

#1


0  

I’m going to separate this answer into two parts: one for appending the user name onto the URL and another for populating the table view.

我将把这个答案分成两个部分:一个用于将用户名附加到URL上,另一个用于填充表视图。

Appending the User Name Onto the URL
Right now, you probably have a string for the URL (we’ll call it URLString) and a text field for the username (we’ll call it usernameTextField). Here is how you would append the contents of the text field to the URL string.

将用户名附加到URL后,URL可能有一个字符串(我们称之为URLString),用户名有一个文本字段(我们称之为usernameTextField)。以下是如何将文本字段的内容附加到URL字符串的方法。

NSString *URLString = @"http://your.domain.goes.here/something?user=";

NSString *userName = [ usernameTextField text ];

NSString *newURLString = [ URLString stringByAppendingString:userName ];

NSURL *URLToLoad = [ NSURL URLWithString:newURLString ];

That gives you an NSURL to use in fetching the data.

Populating the Table View
Here, you want to have a function that loads the data from the URL. Where you currently parse the XML, add in some error-checking that checks to see if the page is valid. If so, you can call

这使您可以使用NSURL来获取数据。在这里填充表视图,您希望有一个从URL加载数据的函数。在当前解析XML的地方,添加一些错误检查,检查页面是否有效。如果是的话,你可以打电话

[ tableView reloadData ];

to reload the table view. In your table view data source’s implementation of the numberOfSectionsInTableView:, numberOfRowsInSection:, cellForRowAtIndexPath:, and other methods, check to see if valid data has been received and, if not, either display no sections and no rows or display a cell with a message to the user to log in.

重新加载表视图。在表视图数据源的numberOfSectionsInTableView:、numberOfRowsInSection:、cellForRowAtIndexPath:和其他方法的实现中,检查是否已收到有效数据,如果没有,则显示无节和无行,或者显示一个单元格,其中包含要登录的消息。

#2


0  

[myTextField text];

this line will extract data from your text field. for login you can use NSMutableURLRequest ot, for rxample, ASIHTTPRequest(this is third-party library) to login. then you can show your tableView in request's delegate method

这一行将从文本字段中提取数据。对于登录,可以使用NSMutableURLRequest ot,对于rxample, ASIHTTPRequest(这是第三方库)来登录。然后可以在request的委托方法中显示tableView

#1


0  

I’m going to separate this answer into two parts: one for appending the user name onto the URL and another for populating the table view.

我将把这个答案分成两个部分:一个用于将用户名附加到URL上,另一个用于填充表视图。

Appending the User Name Onto the URL
Right now, you probably have a string for the URL (we’ll call it URLString) and a text field for the username (we’ll call it usernameTextField). Here is how you would append the contents of the text field to the URL string.

将用户名附加到URL后,URL可能有一个字符串(我们称之为URLString),用户名有一个文本字段(我们称之为usernameTextField)。以下是如何将文本字段的内容附加到URL字符串的方法。

NSString *URLString = @"http://your.domain.goes.here/something?user=";

NSString *userName = [ usernameTextField text ];

NSString *newURLString = [ URLString stringByAppendingString:userName ];

NSURL *URLToLoad = [ NSURL URLWithString:newURLString ];

That gives you an NSURL to use in fetching the data.

Populating the Table View
Here, you want to have a function that loads the data from the URL. Where you currently parse the XML, add in some error-checking that checks to see if the page is valid. If so, you can call

这使您可以使用NSURL来获取数据。在这里填充表视图,您希望有一个从URL加载数据的函数。在当前解析XML的地方,添加一些错误检查,检查页面是否有效。如果是的话,你可以打电话

[ tableView reloadData ];

to reload the table view. In your table view data source’s implementation of the numberOfSectionsInTableView:, numberOfRowsInSection:, cellForRowAtIndexPath:, and other methods, check to see if valid data has been received and, if not, either display no sections and no rows or display a cell with a message to the user to log in.

重新加载表视图。在表视图数据源的numberOfSectionsInTableView:、numberOfRowsInSection:、cellForRowAtIndexPath:和其他方法的实现中,检查是否已收到有效数据,如果没有,则显示无节和无行,或者显示一个单元格,其中包含要登录的消息。

#2


0  

[myTextField text];

this line will extract data from your text field. for login you can use NSMutableURLRequest ot, for rxample, ASIHTTPRequest(this is third-party library) to login. then you can show your tableView in request's delegate method

这一行将从文本字段中提取数据。对于登录,可以使用NSMutableURLRequest ot,对于rxample, ASIHTTPRequest(这是第三方库)来登录。然后可以在request的委托方法中显示tableView