Translate

Tuesday, May 28, 2013

CustomCell

View Didload


objArray = [[NSMutableArray alloc] initWithObjects:
                [[ListObjects alloc] initWithName:@"Steak" andDesc:@"Rare"],
                [[ListObjects alloc] initWithName:@"Steak" andDesc:@"Medium"],
                [[ListObjects alloc] initWithName:@"Salad" andDesc:@"Caesar"],
                [[ListObjects alloc] initWithName:@"Salad" andDesc:@"Bean"],
                [[ListObjects alloc] initWithName:@"Fruit" andDesc:@"Apple"],
                [[ListObjects alloc] initWithName:@"Potato" andDesc:@"Baked"],
                [[ListObjects alloc] initWithName:@"Potato" andDesc:@"Mashed"],
                [[ListObjects alloc] initWithName:@"Bread" andDesc:@"White"],
                [[ListObjects alloc] initWithName:@"Bread" andDesc:@"Brown"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Beef"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Chicken"],
                [[ListObjects alloc] initWithName:@"Hot Dog" andDesc:@"Veggie"],
                [[ListObjects alloc] initWithName:@"Pizza" andDesc:@"Pepperonni"],
                nil ];

cellForRowAtIndexPath

    static NSString *CellIdentifier = @"Cell";
    ThumbCellView *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell = [[ThumbCellView alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil imageName:objArray width:self.view.bounds.size.width];
    cell.backgroundColor=[UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;


ListObjects Class

-(id) initWithName:(NSString*)cateName andDesc:(NSString*)tltName
{
    self = [super init];
    if(self)
    {
        self.catName = cateName;
        self.titleName = tltName;
    }
    return self;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSArray *)imageList width:(int)width
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
          int val;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            if (width==320)
                val=0;
            else
                val=25;
        }
        else
        {
            if (width==768)
                val=0;
            else
                val=25;
        }
        
        for (int i=0;i<[imageList count];i++)
        {
            UIButton* cellBgImg;
            
            if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
            {
                cellBgImg = [[UIButton alloc] initWithFrame:CGRectMake(50+i*140+val, 10, 70, 90)];
            }
            else
            {
                cellBgImg = [[UIButton alloc] initWithFrame:CGRectMake(70+i*180+val, 65, 103, 133)];
            }
            
            UIImage *img=[UIImage imageNamed:@"image.png"];
            [cellBgImg setBackgroundImage:img forState:UIControlStateNormal];
        
[cellBgImg setTitle:[NSString stringWithFormat:@"%d",i+1] forState:UIControlStateNormal];
            cellBgImg.titleLabel.font=[UIFont fontWithName:@"Arial" size:0.0];
            
            cellBgImg.tag=i;
            
[cellBgImg addTarget:self action:@selector(btnpress:) forControlEvents:UIControlEventTouchUpInside];
cellBgImg.backgroundColor=[UIColor clearColor];
            [self addSubview:cellBgImg];
            
        }
    }
    return self;
}

Sunday, May 26, 2013

Apple Push Notification


#pragma mark -
#pragma mark Application lifecycle

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];
    NSLog(@"Registering for push notifications...");    
    [[UIApplication sharedApplication
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound)];
}


- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken1 { 
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *str = [NSString stringWithFormat:@"%@",deviceToken1];
NSLog(@"%@",str);
NSString *stringWithoutOpenB = [str stringByReplacingOccurrencesOfString:@"<" withString:@""];
NSString *stringWithoutCloseB = [stringWithoutOpenB stringByReplacingOccurrencesOfString:@">" withString:@""];
NSString *trimmedString = [stringWithoutCloseB stringByReplacingOccurrencesOfString:@" " withString:@""];
if (standardUserDefaults) {
[standardUserDefaults setObject:trimmedString forKey:@"DT"];
[standardUserDefaults synchronize];
}
    NSLog(@"%@",str);
}

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    NSString *str = [NSString stringWithFormat: @"Error: %@", err];
    NSLog(@"%@",str);  
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    for (id key in userInfo) {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    }    
}