iphone如何使用UITextField传递值cell.detailTextLabel
问题描述:
我的问题是我需要得到用户输入的值然后传递给detailTextlabel,但是我传递给detailtextlabel的地方是null。iphone如何使用UITextField传递值cell.detailTextLabel
我的代码在这里。
- (IBAction) scheduleAlarm:(id) sender {
[eventText resignFirstResponder];
[numText resignFirstResponder];
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
// Break the date up into components
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
//[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
// localNotif.timeZone = [NSTimeZone defaultTimeZone];
//string = [numText.text retain];
string = [[NSString alloc] initWithString:numText.text];
numText = [self numText];
[self.view insertSubview:numText atIndex:1];
NSLog(@"%@",string);
// Notification details
localNotif.alertBody = [eventText text];
// Set the action button
localNotif.alertAction = @"Send SMS";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
//[numText release];
[self.tableview reloadData];
}
在第一次我传递按钮,我可以得到value.but在哪里我去表视图看出来(空)给我。的
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// if (cell == nil) {
// cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
//}
// Configure the cell...
notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications];
UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
// NSString *enNote = [[NSString alloc] initWithString:string];
[cell.textLabel setText:notif.alertBody];
NSString *abc = [NSString stringWithFormat:@"%@ \n %@",[notif.fireDate description], string];
NSLog(@"%@",string);
[cell.detailTextLabel setText:abc];
cell.detailTextLabel.numberOfLines = 2;
//cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
return cell;
}
答
代替cell.detailTextLabel使用cell.textLabel.text
像:
的NSString * ABC = [NSString的 stringWithFormat:@“%@ \ n %@“,[notif.fireDate description], string]; NSLog(@“%@”,string);
cell.textLabel.text = abc;
一个我有函数do.i需要使用cell.detailTextLabel来显示字符串。 – ahyong87 2011-05-04 04:06:49
是detailTextLabel是一个UILabel。如果是UILabel,你可以试试这种方式 [detailTextLabel setText:@“abc”]; cell.contentView = detailTextLabel或[cell.contentView addSubView:detailTextLabel]; – Anand 2011-05-04 04:10:00
no.tat detailtextlabel是在tableview单元格tat one.now我的问题是我cnt通过UITextField获取字符串值。 – ahyong87 2011-05-04 04:16:05