Question: I added buttons to xib as normal using iOS 6 SDK and Xcode 4.5.

When I run the app on iOS 6 simulator, there is no problem. But when I run it on the iOS 5.x simulator (or device), the title on the button always disappears(not every time). Lots of my view controllers have this problem.

![enter image description here](https://i.stack.imgur.com/QxPfV.png)

**PS: Only Custom type button have this problem**

![enter image description here](https://i.stack.imgur.com/wF7Xf.png)

**Found the reason:**  

 [[UIButton appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"取消" forState:UIControlStateNormal]

Answer: 
No, that's trial division which is much worse than the sieve of eratosthenes in time-complexity. Its space complexity is *a bit* better, but, since primes are about `n/log(n)` you are not saving huge quantities of memory. also the sieve can be done using bit-vectors which reduce the *constants* by 32/64 times(and thus for *practical* purposes it might be even better).

---

Small benchmark that shows the difference in timings:

```
>>> timeit.timeit('primes_list(1000)', 'from __main__ import primes_list', number=1000)
0.901777982711792
>>> timeit.timeit('erat(1000)', 'from __main__ import erat', number=1000)
0.2097640037536621

```

As you can see, even with `n=1000` eratosthenes is more than 4 times faster.
If we increase the search up to `10000`:

```
>>> timeit.timeit('primes_list(10000)', 'from __main__ import primes_list', number=1000)
50.41101098060608
>>> timeit.timeit('erat(10000)', 'from __main__ import erat', number=1000)
2.3083159923553467

```

Now eratosthenes is 21 times faster. As you can see it's clear that eratosthenes is **much** faster.

---

using numpy arrays it's quite easy to reduce the memory by 32 or 64(depending on your machine architecture) and obtain much faster results:

```
>>> import numpy as np
>>> def erat2(n):
...     ar = np.ones(n, dtype=bool)
...     ar[0] = ar[1] = False
...     ar[4::2] = False
...     for j in xrange(3, n, 2):
...             if ar[j]:
...                     ar[j**2::2*j] = False
...     return ar.nonzero()[0]
... 
>>> timeit.timeit('erat2(10000)', 'from __main__ import erat2', number=1000)
0.5136890411376953

```

An other 4 times faster than the other sieve.
What you are doing is [trial divison](http://en.wikipedia.org/wiki/Trial_division) - testing each candidate prime against each known prime below it. Skipping odd numbers in the call to `range` will save you some divisions, but this is exactly the technique sieveing is based on: you know that every second number is divisible by 2, and therefore composite. The sieve just extends this to:

* every third number is divible by three, and therefore composite;
* every fifth by five, and therefore composite

and so on. Since the Sieve is regarded as one of the most time-efficient algorithms available, and trial division as one of the *least* (wikipedia describes the sieve as `O(n log log n)`, and per the comments below, your algorithm is likely `O(n^2 / log n)`) ) , it is reasonable to assume that trial division with some Sieve-like optimisation falls short of sieving.