将变量添加到LocatNotification错误是未使用属性访问结果 - 不应将getter用于副作用

时间:2014-06-28 15:10:42

标签: ios objective-c uitableview variables uilocalnotification

尝试了解如何在本地通知的.alertBody部分插入变量。我希望插入cell.deviceNameLabel.class。我不知道这是怎么做的。如果我使用纯文本,则本地通知有效。

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  static NSString *CellIdentifier = @"MyReusableCell";
  SightingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

  if (cell != nil) {
      Device *device = [self.transmitters objectAtIndex:indexPath.row];

      // Update the device text
     cell.deviceNameLabel.text = device.name;

     // Update the device avatar (icon image)
     NSInteger avatarID = [UserSettingsRepository getAvatarIDForTransmitterID:device.identifier];
     NSString *imageFilename = [NSString stringWithFormat:@"avatar_%02ld.png", (long)avatarID];
     cell.transmitterIcon.image = [UIImage imageNamed:imageFilename];

     if ([self isTransmitterAgedOut:device]) {
         [self grayOutSightingsCell:cell];
         //Add Local Notification
         NSDate *AlertTime = [[NSDate date] dateByAddingTimeInterval:3];
         UIApplication *app = [UIApplication sharedApplication];
                               UILocalNotification *notifyAlert = [[UILocalNotification alloc] init];
                               if (notifyAlert) {
                                   notifyAlert.timeZone = [NSTimeZone defaultTimeZone];
                                   notifyAlert.repeatInterval = 0;
                                   notifyAlert.soundName = @"soundeffect.mp3";
                                   notifyAlert.alertBody = @"%@ went out of range", cell.deviceNameLabel.class;
                                   notifyAlert.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
                                   [app scheduleLocalNotification:notifyAlert];
                                    }
     } else {
         [self updateSightingsCell:cell withTransmitter:device];
     }
 }
 return cell;

1 个答案:

答案 0 :(得分:0)

使用:

[NSString stringWithFormat:@"%@ went out of range", NSStringFromClass(cell.deviceNameLabel.class);