Cocoa-Matic

iPhone, iPod touch, iPad tutorials, examples and sample code. Come and get it!

Wednesday, August 18, 2010

Prevent UITableView from scrolling

Quick tip:

UITableView elements enable vertical scrolling by default. The following code disables the scroll:
myTableView.scrollEnabled = NO;

Labels: , , ,

Tuesday, August 17, 2010

Random Number in Cocoa and Objective-c

Generating a random number is fairly simple using arc4random(). Say you want a random integer between 10 (min) and 1000 (max). Here's how to do it:

int max = 1000;
int min = 10;
int value = (arc4random() % max) + min;

Also, no need to do any seeding with this method.

Labels: ,

Friday, August 13, 2010

Unwanted UITableView gray background on iPad

I came across something weird when developing an iPad app. I have a UITableView that does not encompass the entire screen and I have it set to grouping mode so it has nice looking rounded corners. For some reason when this is displayed, the background of the UITableView is light gray. It seems to be ignoring the backgroundColor property.

So, here's the fix:
Read more »

Labels: , , ,

Asynchronous data request class

A very handly class I've built is asyncDataRequest. This provides for an easy way to make and receive calls to web data feeds. All you have to do is include the class reference in your .m file, make the request and create a notification responder to receive and parse that data response.

First, we'll look at asyncDataRequest.h:
@interface asyncDataRequest : NSObject {
 NSMutableData *responseData;
 id delegate;
 NSString *notificationName;
}

@property(nonatomic,retain) NSMutableData *responseData;
@property(nonatomic,assign) id delegate;
@property(nonatomic,retain) NSString *notificationName;

- (void)setDelegate:(id)newDelegate;
- (void)connection:(NSURLConnection *)connection didReceiveResponse: (NSURLResponse *)response;
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;
- (void)connection:(NSURLConnection *)connection didFailWithError: (NSError *)error;
- (void)connectionDidFinishLoading: (NSURLConnection *)connection;

@end

Read more »

Labels: , , , ,


« Older Entries  
Newer Entries »