开发者

iphone how to i get text field value pass to tableview?

i want do gave user fill in number to text field, then i need get the user value pass to table view cell.detailTextLabel ?any one know how to do this?..

my code here.

at .h i have

IBOutlet UITextField *numText;
NSString *string;

then at .m

when button click i can see the value at string.

- (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];
    string = numText.text;

    test = [[NSMutableArray alloc] init];
    [test addObject:string];

//  self.num = array;
    //[num release];




    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];
    //[test release];
    [self.tableview reloadData];

}

when i go to UITableView i cnt pass any value to here.all is null and i use UITabBarController 1st tab is gave user fill in number and event.then at second tab i need to show user fill in value to tableview.

- (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 sh开发者_Python百科aredApplication] scheduledLocalNotifications];
    UILocalNotification *notif = [notificationArray objectAtIndex:indexPath.row];
   //  NSString *enNote = [[NSString alloc] initWithString:string];
   NSString *nomber = [test objectAtIndex:indexPath.row];
    NSLog(@"nomber in get test %@",nomber);


    [cell.textLabel setText:notif.alertBody];

    NSString *abc = [NSString stringWithFormat:@"%@ \n %@",[notif.fireDate description], numText.text];
    NSLog(@"%@",nomber);
    [cell.detailTextLabel  setText:abc];
    cell.detailTextLabel.numberOfLines = 2;

    //cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;




    return cell;
}


create an nsmutablearray and add the value you get from textfield to that array and in the method

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
cell.textlabel.text = [yourarray objectatindex:index];
}

And on your buttonclick call

[yourtable reloaddata];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜