当单元格灰显时,我想创建一个本地通知。在alertBody中,希望文本读取单元格中的内容并将其发送到本地通知。只有警报!显示没有.alertBody。尝试了几种不同的方法,但没有成功获得本地警报以显示灰色单元格中的内容。
TableViewController.h
@property(nonatomic,retain)UITextField * transmitterNameLabel;
TableViewController.m
@synthesize transmitterNameLabel;
...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"MyReusableCell";
SightingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell != nil) {
Transmitter *transmitter = [self.transmitters objectAtIndex:indexPath.row];
// Update the transmitter text
cell.transmitterNameLabel.text = transmitter.name;
// Update the transmitter avatar (icon image)
NSInteger avatarID = [UserSettingsRepository getAvatarIDForTransmitterID:transmitter.identifier];
NSString *imageFilename = [NSString stringWithFormat:@"avatar_%02ld.png", (long)avatarID];
cell.transmitterIcon.image = [UIImage imageNamed:imageFilename];
if ([self isTransmitterAgedOut:transmitter]) {
[self grayOutSightingsCell:cell];
//Add Local Notification
NSDate *AlertTime = [[NSDate date] dateByAddingTimeInterval:3];
UIApplication *app = [UIApplication sharedApplication];
UILocalNotification *notifyAlert = [[UILocalNotification alloc] init];
if (notifyAlert) {
notifyAlert.fireDate = AlertTime;
notifyAlert.timeZone = [NSTimeZone defaultTimeZone];
notifyAlert.repeatInterval = 0;
notifyAlert.soundName = @"soundeffect.mp3";
notifyAlert.alertBody = transmitterNameLabel.text;
notifyAlert.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[app scheduleLocalNotification:notifyAlert];
}
} else {
[self updateSightingsCell:cell withTransmitter:transmitter];
}
}
return cell;
答案 0 :(得分:0)
更新标签时,请致电cell.transmitterNameLabel.text = transmitter.name;
,更新transmitterNameLabel
类对象SightingsTableViewCell
中的cell
属性,但在设置alertBody
时,调用notifyAlert.alertBody = transmitterNameLabel.text;
,它不是cell
对象的属性,因此可能是空的/不同的。
也许您应该尝试notifyAlert.alertBody = cell.transmitterNameLabel.text;
?