Tag Archives: iPhone

How to create UIButton that looks like UITableViewCell with AccessoryIndicator

Sometimes you need to create only one button, that looks like a UITableViewCell with accessory indicator. Users are familiar with this control and they know that if they click it, something should appear. For example, it can be used in different forms to select something after user taps a button. Using a UITableView with one section and cell is too complex approach if you need only one such button. Even if you need some more such buttons, you can use this solution to make code a little simpler.

I created an instance of UIButton and reached this goal after some search in StackOverflow and my own attempts. Finally, my button looks like this:
DKAccessoryButton

Yes, it is a UIButton, not UITableViewCell. So, how I did it?

You can look at my repository on GitHub, I have published a source code of such button under MIT Licence Terms.
DKAccessoryButton: https://github.com/wzbozon/DKAccessoryButton

How to export a file to iPhone documents folder programmatically

Here I give an example of how to export a file to iPhone documents folder programmatically. I spent a lot of time on managing of how to do it. My main problem was that I couldn’t find documents folder of iPhone simulator. I couldn’t write anything to file and I used a wrong way with NSData class. Finally, I found a recipe in Internet and modified it a little bit.

So look at the example:

This is just a method. Firstly, we discover a documents Directory of a device. Then we NSLog it in order to find that directory on Mac, if we use iPhone/iPad simulator. Then we make a file name to write the data to using the documents directory. Then create content – four lines of text, including even some non ASCII text(that’ the modification). Then we just save content to the documents directory. Now that file is available through iTunes in programs tab, in the bottom of it for the given Applicaton. Note that you should add “Application supports iTunes file sharing” line and check it in your Info.plist file for your application in order to be able to use iTunes/iPhone/Programs/Your app to share files. Also note that encoding:NSUTF8StringEncoding is needed if you want to use non ASCII letters.

[crayon-662cb1c824972584600720/]