- (void)viewDidLoad
{
[super viewDidLoad];
[self tableInfo];
}
- (void) tableInfo
{
NSArray *keysArray = @[@"CampaignsName",@"BusinessName",@"BusinessType",@"CampaignsType",@"Distance",@"Daysleft",@"CampaignImage",];
NSArray *valuesArray1 =[NSArray arrayWithObjects:@"5 % OFF ",@"Coffe Shop",@"1",@"1",@"0.10 Miles",@"5 days Left",@"b2.png", nil];
NSArray *valuesArray2 = [NSArray arrayWithObjects:@"win $2 for you & charity ",@"Red Tommato",@"2",@"2",@"20 Miles",@"2 days Left",@"b1.png", nil];
NSArray *valuesArray3 = [NSArray arrayWithObjects:@"Buy dogs food & get a one more",@"Pet Care",@"3",@"3", @"30 Miles",@"10 days Left",@"b2.png", nil];
NSArray *valuesArray4 =[NSArray arrayWithObjects:@"win $2 for you & charity ",@"Red Tommato",@"1",@"1",@"0.10 Miles",@"7 days Left",@"b2.png", nil];
NSDictionary *dict1 = [NSDictionary dictionaryWithObjects:valuesArray1 forKeys:keysArray];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjects:valuesArray2 forKeys:keysArray];
NSDictionary *dict3 = [NSDictionary dictionaryWithObjects:valuesArray3 forKeys:keysArray];
NSDictionary *dict4 = [NSDictionary dictionaryWithObjects:valuesArray4 forKeys:keysArray];
self.tableArray = [[NSArray alloc]initWithObjects:dict1,dict2,dict3,dict4,dict3,dict1,dict4,dict2,nil];
NSLog(@"Array %@",tableArray);
[self.tableObj reloadData];
}
#pragma mark table view datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self tableCustomView:tableView cellForRowAtIndexPath:indexPath];
return cell;
}
- (UITableViewCell *)tableCustomView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *mainCell ;
static NSString *CellIdentifier1 = @"CustomCellIdentifier";
static NSString *CellIdentifier2 = @"CustomCellIdentifier2";
if (indexPath.row % 2 != 0)
{
CustomCell2 *cell2 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell2 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell2" owner:self options:nil];
cell2 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell2.CampaignsNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsName"]];
cell2.BusinessNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessName"]];
cell2.DistanceLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Distance"]];
cell2.DaysleftLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Daysleft"]];
cell2.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessType"]] integerValue];
NSLog(@": %d",businessType);
switch (businessType)
{
case 1:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"RETL@2x.png"];
break;
case 2:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"BTY.png"];
break;
case 3:
cell2.cellBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t3.png"];
break;
case 2:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t2.png"];
break;
case 3:
cell2.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"];
break;
default:
break;
}
mainCell = cell2 ;
}
else
{
CustomCell1 *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell1 == nil)
{
NSArray *topObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell1" owner:self options:nil];
cell1 = [topObjects objectAtIndex:0];
}
id object = [self.tableArray objectAtIndex:indexPath.row];
cell1.CampaignsNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsName"]];
cell1.BusinessNameLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessName"]];
cell1.DistanceLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Distance"]];
cell1.DaysleftLbl.text = [NSString stringWithFormat:@"%@",[object valueForKey:@"Daysleft"]];
cell1.cellBackImg.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignImage"]]];
int businessType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"BusinessType"]] integerValue];
NSLog(@": %d",businessType);
switch (businessType)
{
case 1:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"RETL@2x.png"];
break;
case 2:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"BTY.png"];
break;
case 3:
cell1.cellBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"];
break;
default:
break;
}
int CampaignsType = [[NSString stringWithFormat:@"%@",[object valueForKey:@"CampaignsType"]] integerValue];
switch (CampaignsType)
{
case 1:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t3.png"];
break;
case 2:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t2.png"];
break;
case 3:
cell1.cellOverLayBusinessTypeImg.image = [UIImage imageNamed:@"t1.png"];
break;
default:
break;
}
mainCell = cell1 ;
}
return mainCell;
NSLog(@"Index Path is :%d %d", indexPath.section,indexPath.row);
}
UIViewController
很奇怪的人吗? - sooper