how do i authenticate the user and load a table view on success?
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 figur开发者_如何学Ced 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..
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.
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.
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
[ 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.
[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
精彩评论