开发者

load MySQL results into UITableView (iPhone)

I am making an iphone app which needs to draw information directly form a MySQL database, however, I have no idea how to go about doing that. does开发者_开发百科 anyone have any open source samples or walkthroughs on how to do this?

Thank!


You can you this API hosted on github.com .

https://github.com/gwdp/Obj-c-MySql

It's free and very well documented .


you can create an sqlite file from your database, and then import that file to your project.And access that sqlite file same as you fire sql query.See tutorials of accessing sqlite file.


I would look into the NSURLConnection documentation on how to load data from a remote server. Create a web service in your remote server that will return data in XML or JSON depending on the request sent from your app and have your app populate your cells using the returned data.

One naive approach is to send a request to a PHP page. You can write the request like this to post to your php page:

  NSString* content = [@"value=getAll"];

  NSURL* url = [NSURL URLWithString:@"http://www.url.com/pagetopost.php"];
  NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
  [urlRequest setHTTPMethod:@"POST"];
  [urlRequest setHTTPBody:[content dataUsingEncoding: NSASCIIStringEncoding]];

Your PHP would have code that will fetch from the MySQL DB depending on the POST value sent in and return the data as JSON.

Then you will have to handle the response and maybe put that in an array that will be populated to your table view cells.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜