繁体   English   中英

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

[英]Adding variable to LocatNotification error is Property access result unused - getters should not be used for side effects

试图了解如何在本地通知的.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;

采用:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM