If you have a form like adding contact or event etc., then you need to scroll your view according to the position of your textfield. Because keyboard or picker view will probably hides it if you don't. One easy way to do is to set the content offset of your UIScrollView as follows when you click the textfield:
[scrollView setContentOffset:CGPointMake(x, y) animated:YES];
Monday, February 14, 2011
Monday, February 7, 2011
How to set the font of UIToolBarItem
As far as I know, there is no easy way to directly set the font of (such as title etc.) UIToolBarItem. However, one can create a UILabel and use initWithCustomView method of UIToolBarItem to get works done. In this way, changing the font of a UIToolBarItem is just the matter of changing the font of UILabel.
Friday, February 4, 2011
Comments on memory leaks
If you are getting memory leaks but couldn't find the underlying reason, I found this to be very useful:
"This sounds like it could be one of a few things:
Memory not given back to OS after deallocation. This is a common design for C runtimes. When you do an allocation the C runtime allocates more memory for its use and returns a chunk of it for you to use. When you do a free the C runtime simply marks it as deallocated but doesn't return it back to the OS. Thus if the Leak Tool is reading OS level statistics rather than C runtime statistics the Leak tool will fail to report a corresponding decrease in memory usage.
Misleading values reported by Leak Tool Memory. The Leak Tool could be looking at different values than the C runtime and is reporting values that will cause you concern even though nothing is wrong (just as people try to use Task Manager in Windows for detecting leaks and get very confused with the results because it is a very poor tool indeed for that job).
Fragmentation. It is possible that your application is suffering from memory fragmentation. That is when you allocate, then deallocate then allocate, subsequent attempted allocations are larger than the "holes" left by deallocations. When this happens you fragment the memory space, leaving unusable holes, preventing large contiguous memory blocks and forcing the usage of more and more memory space until you run out of memory. This is a pathological condition and the fix is typically application specific."
http://stackoverflow.com/questions/2339279/memory-leak-tool-tells-me-zero-leaks-but-memory-footprint-keeps-rising
"This sounds like it could be one of a few things:
Memory not given back to OS after deallocation. This is a common design for C runtimes. When you do an allocation the C runtime allocates more memory for its use and returns a chunk of it for you to use. When you do a free the C runtime simply marks it as deallocated but doesn't return it back to the OS. Thus if the Leak Tool is reading OS level statistics rather than C runtime statistics the Leak tool will fail to report a corresponding decrease in memory usage.
Misleading values reported by Leak Tool Memory. The Leak Tool could be looking at different values than the C runtime and is reporting values that will cause you concern even though nothing is wrong (just as people try to use Task Manager in Windows for detecting leaks and get very confused with the results because it is a very poor tool indeed for that job).
Fragmentation. It is possible that your application is suffering from memory fragmentation. That is when you allocate, then deallocate then allocate, subsequent attempted allocations are larger than the "holes" left by deallocations. When this happens you fragment the memory space, leaving unusable holes, preventing large contiguous memory blocks and forcing the usage of more and more memory space until you run out of memory. This is a pathological condition and the fix is typically application specific."
http://stackoverflow.com/questions/2339279/memory-leak-tool-tells-me-zero-leaks-but-memory-footprint-keeps-rising
Tuesday, February 1, 2011
Memory Management in Objective-C
Memory management in Objective-C is inspired by C/C++. It is mostly similar and also a little bit easier than C/C++. One has to release any object at the end of the program that has retain count of greater one so that there is no memory leak. Retain count is increased by a few operations such as alloc, retain and copy. There is also the concept of autorealese which is very similar to the local variables in C/C++.
Another important thing is one does not have to release primitive types like NSInteger which are stored in the stack and poped up at the end of the program execution.
Another important thing is one does not have to release primitive types like NSInteger which are stored in the stack and poped up at the end of the program execution.