I am trying to change the custom cell that will be used depending on information stored in my array. I have tried everything but cannot seem to get it working without an error. The code does not seem to accept a string input for the cell nib. Is there any other way to do this? Will attach my code below.
Thanks.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[Tutortrackinbud[indexPath.row] valueForKey:@"reply"] isEqual: @"N"])
{
nib = @"ReviewCell1";
}
else{
nib = @"ReviewCell2";
}
static NSString *simpleTableIdentifier = nib;
ReviewCell1TableViewCell *cell = (ReviewCell1TableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:nib owner:self options:nil];
cell = [nibArray objectAtIndex:0];
}
if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"1"]){
NSLog(@"1");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"greystar.png"];
cell.star3.image = [UIImage imageNamed:@"greystar.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"2"]){
NSLog(@"2");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"greystar.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"3"]){
NSLog(@"3");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"greystar.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"4"]){
NSLog(@"4");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"greystar.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"5"]){
NSLog(@"5");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"star.png"];
cell.star6.image = [UIImage imageNamed:@"greystar.png"];
}
else if ([[Tutortrackinbud[indexPath.row] valueForKey:@"stars"] isEqual: @"6"]){
NSLog(@"6");
cell.star1.image = [UIImage imageNamed:@"star.png"];
cell.star2.image = [UIImage imageNamed:@"star.png"];
cell.star3.image = [UIImage imageNamed:@"star.png"];
cell.star4.image = [UIImage imageNamed:@"star.png"];
cell.star5.image = [UIImage imageNamed:@"star.png"];
cell.star6.image = [UIImage imageNamed:@"star.png"];
}
cell.reviewdate.text = [Tutortrackinbud[indexPath.row] valueForKey:@"date"];
cell.reviewtext.text = [NSMutableString stringWithFormat:@"%@ -%@",[Tutortrackinbud[indexPath.row] valueForKey:@"desc"],[Tutortrackinbud[indexPath.row] valueForKey:@"username"]];
//cell.tutortext.text = [NSMutableString stringWithFormat:@"%@ -%@",[Tutortrackinbud[indexPath.row] valueForKey:@"desc"],[Tutortrackinbud[indexPath.row] valueForKey:@"username"]];
cell.tutortext.text = @"this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test this is test";
return cell;
}