#iphone #uitextfield #tableview
#iPhone #uitextfield #просмотр таблицы
Вопрос:
Моя проблема в том, что мне нужно, чтобы пользователь вводил значение, а затем передавал в detailTextLabel, но там, где я передаю в 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];
}
при первом нажатии кнопки я могу получить значение. но там, где я перехожу к просмотру таблицы, для меня значение out (null).
- (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;
}
Ответ №1:
вместо cell.detailTextLabel используйте cell.textLabel.text
Нравится:
NSString *abc = [NSString stringWithFormat:@»%@ n %@»,[описание notif.fireDate], строка]; NSLog(@»%@», строка);
cell.textLabel.text = abc;
Комментарии:
1. это одна из функций, которую я должен выполнить. мне нужно использовать cell.detailTextLabel для отображения строки.
2. Является ли detailTextLabel UILabel. Если это UILabel, вы можете попробовать этот способ [detailTextLabel setText:@»abc»]; cell.contentView = detailTextLabel или [cell.contentView добавляет SUBVIEW:detailTextLabel];
3. нет. эта detailtextlabel находится в ячейке tableview tat one. теперь моя проблема в том, что я не могу получить строковое значение с помощью UITextField.
4. итак, я понял, к чему ты клонишь. Теперь вы пытаетесь, это сработает, если (cell == nil) {cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 повторно использовать идентификатор ячейки] авторелиз]; }
5. хммм, нет этого. теперь мой вопрос в том, что у меня есть IBOutlet UITextField * numText; используйте interfacer builder.где я заполняю numText, я получил значение; затем мне нужно перейти в табличное представление, используя cell.detailTextLabel, чтобы отобразить numText при заполнении.