#ios #objective-c #uitableview #variables #uilocalnotification
#iOS #objective-c #uitableview #переменные #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_ld.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:
Использовать:
[NSString stringWithFormat:@"%@ went out of range", NSStringFromClass(cell.deviceNameLabel.class);
Комментарии:
1. Ответы намного лучше работают с текстом, объясняющим их. Объяснения облегчают обучение. Из-за этого этот ответ фактически появился в очереди просмотра для сообщений низкого качества.
2. Привет, спасибо за ваш ответ, это сработало, и теперь я лучше понимаю. Он вернул className UILabel, а не то, что я ожидал, но теперь понимаю лучше. Я хотел, чтобы он возвращал текстовое значение в ячейке, полученной из файла .h — @property (слабый, неатомный) IBOutlet UILabel *transmitterNameLabel;