简体   繁体   中英

Using data from a web-service in an iOS Application

I have to list the table entries from mysql in my iPhone app when a button is pressed. I am able to do it properly but it is just not the way I want it. I am using a PHP script to send Xcode what has to be printed.

First, I tried doing it using HTML table, but I didn't like the way it was printed with cells. Next I tried printing plain text by giving spaces(between columns) and \\n for every new row. I used NSURL and loaded the webView to the iPhone. Looks good on browser but the same is not preserved when the iPhone tries to open it.

Is there a good way to do this? So I can just list the table entries without having to go through the traditional HTML table or any other idea is welcome.

Also, please try to be easily understood, as I am new to Obj-C, and PHP as well. Thanks!!

Any thoughts on how I can do this in a UITableView ..?? Do I have to return a string with component separation characters and fill in the tableView ?

Output the results encoded in JSON. Send an a(sync) request to the server using NSURLConnection or using a third-party library such as AFNetworking. Parse the JSON using NSJSONSerialization, turning the results into an array/dictionary depending on the contents. Then parse the results into the UITableViewCell. It may be easier to subclass the cell so that you include the data that you'd like to use.

To encode the results from the database into JSON, you can use the method json_encode() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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