Skip to content

Instantly share code, notes, and snippets.

View romyilano's full-sized avatar
😎
improving

Romy romyilano

😎
improving
View GitHub Profile
@romyilano
romyilano / Scroller.m
Created February 10, 2013 17:10
manually setting the scroller size in a UIViewController change the contentSize property
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.theScroller.contentSize=CGSizeMake(280.0,1000.0);
}
@romyilano
romyilano / jsonmagic.m
Created February 14, 2013 02:14
NSJSONSerialization - this class kicks @$$!
NSError *error;
// turn the responseData into an NSDictionary object
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray *latestLoans = json[@"loans"];
NSDictionary *loan = latestLoans[0];
// build an info object out of the dictionary
// this is a new way to write dictionaries as of iOS6
NSDictionary *info = @{
@"who":loan[@"name"];
// here i register a MPMusicPlayerController object to the NSNotificationCenter
MPMusicPlayerController *musicPlayer =
[MPMusicPlayerController applicationMusicPlayer];
[musicPlayer setQueueWithItemCollection: userMediaItemCollection];
[musicPlayer beginGeneratingPlaybackNotifications];
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter
@romyilano
romyilano / conveyerbelt.m
Created February 23, 2013 07:02
creating alternating cell types
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier;
// nice! make the conditional here
if ((indexPath.row %2) == 0 ) {
CellIdentifier = @"rowOdd";
} else {
CellIdentifier = @"rowEven";
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = [NSString stringWithFormat:@"%d", indexPath.row];
label = (UILabel *)[cell viewWithTag:2];
label.text = [NSString stringWithFormat:@"%d", NUMBER_OF_ROWS - indexPath.row];
@romyilano
romyilano / customheader+footer.m
Created February 26, 2013 02:56
custom header and footer to a UITableView (programmatically) nice! from apress.com pro ios tableviews for iphone
@romyilano
romyilano / subviews.m
Created February 26, 2013 04:23
access the subviews in a UIView by iterating through its array of subVIews
for (UIView *theSubView in parentView.subViews) {
// do something to the subView
}
@romyilano
romyilano / customuitableviewcell.m
Created February 26, 2013 04:26
Creating a UILabel without nib files in a custom uITableViewCell... apress.com pro iOS table views
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"cellIdentifier";
UITableVIewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableVIewCell alloc] initWithStyle:UITableVIewCellStyleDefault resuseIdentifier:cellIdentifier];
// create a new label with the size we need
UILabel *myLabel = [[UILabel alloc] init];
@romyilano
romyilano / TableViewController.m
Created February 27, 2013 03:41
using tags without any need for subclassing a UITableViewCell - UITableView in iOS apress.com
-(UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
UILabel *cellLabel;
cellLabel = (UILabel *)[cell viewWithTag:1000];
cellLabel.text = [tableData objectAtIndex:indexPath.row];
UIImageView *cellIcon = (UIImageView *)[cell viewWithTag:1010];
@romyilano
romyilano / gist:5044929
Created February 27, 2013 03:56
Programmatically creating UITableViewCell Autolayout and struts in code apress.com Pro iOS TableViews for iPhone
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableVIewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}