7
« on: April 01, 2014, 05:04:32 AM »
Hi, i keep getting the error "Invalid argument type 'NSString' to unary expression' when following step two. I am sure the code is identical to yours, I even did a copy/paste from the book. I believe i may have misunderstood where the code should be placed though. Maybe you could clarify? I've attached a photo of the code, as well as the code in text-format. It is the top NSString that is causing an issue.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- (NSString *)tableView:(UITableView *)
tableView titleForHeaderInSection:
(NSInteger)section {
switch (section) {
case 0:
return @"Customer Information";
break;
case 1:
return @"Shipment Detail";
break;
default:
return nil;
}
}
- (NSString *)tableView:(UITableView *)
tableView titleForFooterInSection:
(NSInteger)section {
switch (section) {
case 0:
return @"Be kind and courteous!";
break;
default:
return nil;
break;
}
}
UITableViewCell *cell;
// Configure the cell...
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:@"NameCell" forIndexPath:indexPath];
cell.textLabel.text = self.shipmentEntity.name;
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"AddressCell" forIndexPath:indexPath];
cell.textLabel.text = self.shipmentEntity.address;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@ %@",
self.shipmentEntity.city,
self.shipmentEntity.region,
self.shipmentEntity.postalCode];
break;
case 2:
cell = [tableView dequeueReusableCellWithIdentifier:@"PhoneCell" forIndexPath:indexPath];
cell.detailTextLabel.text = self.shipmentEntity.phone;
break;
case 3:
cell = [tableView dequeueReusableCellWithIdentifier:@"TextCell" forIndexPath:indexPath];
cell.detailTextLabel.text = self.shipmentEntity.text;
break;
case 4:
{
cell = [tableView dequeueReusableCellWithIdentifier:@"DeliveryStatusCell" forIndexPath:indexPath];
NSString *typeLabel =
[[self.shipmentEntity deliveryStatus] valueForKey:@"statusDescription"];
cell.detailTextLabel.text = typeLabel;
break;
}
case 5:
cell = [tableView dequeueReusableCellWithIdentifier:@"ShipmentIDCell" forIndexPath:indexPath];
cell.detailTextLabel.text = self.shipmentEntity.shipmentID;
break;
default:
break;
}
}
else if (indexPath.section == 1)
{
ShipmentItemEntity *shipItem = [shipmentItemList objectAtIndex:indexPath.row];
cell = [tableView dequeueReusableCellWithIdentifier:@"ShipmentItemCell" forIndexPath:indexPath];
cell.textLabel.text = [NSString stringWithFormat:@"(%u) %@",
shipItem.quantity,
shipItem.itemDescription];
//Change the image of an Apple TV (badboy)
if ([shipItem.itemDescription rangeOfString:@"Badboy"].location != NSNotFound) {
cell.imageView.image = [UIImage imageNamed:@"AppleTVCellImage.png"];
}
}
return cell;
}